Force R to plot histogram as probability (relative frequency)

前端 未结 5 2078
面向向阳花
面向向阳花 2021-01-31 05:40

I am having trouble plotting a histogram as a pdf (probability)

I want the sum of all the pieces to equal an area of one so it\'s easier to compare across datasets. For

5条回答
  •  耶瑟儿~
    2021-01-31 06:17

    R has a bug or something. If you have discrete data in a data.frame (with 1 column), and call hist(DF,freq=FALSE) on it, the relative densities will be wrong (summing to >1). This shouldn't happen as far as I can tell.

    The solution is to call unlist() on the object first. This fixes the plot. enter image description hereenter image description here (I changed the text too, data from http://www.electionstudies.org/studypages/anes_timeseries_2012/anes_timeseries_2012.htm)

提交回复
热议问题