[R] histogram - density on y axis and restriction to interval [0, 1]

Christine SINOQUET christine.sinoquet at univ-nantes.fr
Thu Jun 9 18:22:20 CEST 2011


Hello,

To indicate probability densities instead of counts on a histogram, I 
specify freq = FALSE.

However, I expect that summing all top y coordinates over all the 
intervals of the histogram will provide 1.

1)
v <- c(0.2885, 0.2988, 0.3139, 0.2615, 0.3179, 0.3163, 0.2583, 0.3052, 
0.2527, 0.3147, 0.3235, 0.2408, 0.2480, 0.3108, 0.3577, 0.2829, 0.2694, 
0.3275, 0.3314, 0.2639, 0.3076, 0.3346, 0.2933, 0.3585, 0.2678, 0.3338)

hist(v, freq = FALSE)

With the above example, roughly, I obtain 3 * 8 + 10 + 14 + 4 = 52

Besides, I do not understand the units on the y axis. I would have 
expected decimals.

2) In contrast, I am satisfied with the units on the y axis with the 
example below :
  v <- 
c(1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,4,4,4,4,4,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,8,8,8,8,8,9,9,9,9,9) 

hist(v, freq = FALSE)


3) Again, with the example below, I wonder why the unit axis does not 
show the interval [0,1] (or maybe [0%,100%]). Proportions are correct 
but the indication 1.4 is not usual.

v <- c(1,2,2,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4)
 > hist(v, freq = FALSE)


I thank you in advance for any explanation about the way to force the y 
axis to restrain to interval [0,1] on an histogram.

Best regards,

Christine Sinoquet



More information about the R-help mailing list