Hi Miao,

With option freq=FALSE, the function hist calculates densities, i.e. in your 
case,
counts/total/length in-between breaks.

h <- hist(Y1, breaks=seq(0, 350, by=35),freq=FALSE)



If you calculate: 
h$counts/sum(h$counts)/35 = h$density

Regards,
Pascal

----- Mail original -----
De : jpm miao <miao...@gmail.com>
À : r-help@r-project.org
Cc : 
Envoyé le : Lundi 12 mars 2012 16h42
Objet : [R] A question on histogram - area much less than 1

Hello,

   I have problem running the histogram function "hist". The area under the
histogram is much lower than 1. Could anyone tell me what the problem is?
Thanks,
   (The total number of observation is 992 (close to 1000), so the
probability that 0<Y1<35 is approximately 0.277)

miao



rm(list=ls())
par(mfrow=c(1, 1))
Y <- cbind(matrix(35*0.5,1,277), matrix(35*1.5, 1, 146), matrix(35*2.5, 1,
99), matrix(35*3.5,1,80), matrix(35*4.5, 1, 69), matrix(35*5.5, 1, 63),
matrix(35*6.5, 1, 52), matrix(35*7.5,1, 53), matrix(35*8.5, 1, 55),
matrix(35*9.5, 1, 98))
Y1<-as.vector(Y)
par(mar=c(4.5, 4.1, 3.1, 0))
hist(Y1, breaks=seq(0, 350, by=35), ylim=c(0, 0.3), col="grey80",
freq=FALSE)
par(mar=c(5.1, 4.1, 4.1, 2.1))

    [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to