Reputation: 23
I want to plot a relative frequency histogram in R, of this data:
0.1575850 0.1378830 0.1462112 0.1303224 0.3538677 0.2497142 0.2359662 0.1647894 0.1861195 0.3957871 0.2135463 0.1584121 0.1690736 0.4232640 0.2058885 0.1615527 0.3250968 0.1529143 0.5984977 0.2334365 0.2141899 0.1495538
I want to use seq(0,1,0.2) for the argument "breaks", and set freq=FALSE to get the DENSITY (not the counts) plot. Based on what the hist function help states, I would expect that the total area of the relative frequency histogram (or the sum of $density) would be equal to one, but instead I'm getting this:
cc$density [1] 2.5000000 2.0454545 0.4545455 0.0000000 0.0000000
Any suggestions of what could be happening? I tried to use the histogram function of {lattice}, and the histogram seems fine, but I couldn't change the size of the label and axis test using the regular aruments (cex.lab and cex.axis).
Thanks for your help and time.
Upvotes: 2
Views: 366
Reputation: 4094
Hint: sum(cc$density) == 5
, and 5 * 0.2 == 1
. (You can stop reading here, or...)
To calculate an area under the bar plot curve, you have to multiply the height of each bar (which is what cc$density
gives you) by width of each bar, which is 0.2 in your case.
Upvotes: 1