# sum of probabilities doesn't match, using HistogramTools in R

I was using the package HistogramTools in R to create Histogram.

> H<-hist(1:100)
> sum(H$density) [1] 0.1  Somehow the sum of the density is not 1, regardless of the data I use (I have tried several generated random data as well, and it is also not 1) but then, > sum(H$counts)
[1] 100


the total counts match the total number of data.

Am I wrong in understanding "density" or "relative frequency"??

• You would find it informative to plot H. – whuber Sep 23 at 19:54
• Pretty sure this is essentially a duplicate. Its sort of covered in Silverfish's answer here but I think there's an answer (maybe from whuber) elsewhere that's more direct. I just don't seem to be turning it up right now. – Glen_b -Reinstate Monica Sep 24 at 3:21

$density property of an histogram object gives you the y-axis values of each bin. In order to get an area of $$1$$, you'll have to multiply it with the bin width. In your case, number of bins is 10 by default, which gives you a bin width of 10. Multiplying it with H$density gives $$1$$. Try the following, which will give 0.2 when executed (here bin width will be 5):

H<-hist(1:100, 20)
sum(H\$density)