test <- rep(5,20)
hist(test,freq=FALSE,breaks=5)
The vector contains 20 times the value 5. When I plot this with freq=FALS
E and b
hist
plots an estimate of the probability density when freq=FALSE
or prob=TRUE
, so the total area of the bars in the histogram sums to 1. Since the horizontal range of the single bar that is plotted is (0,5), it follows that the height must be 0.2 (5*0.2=1)
If you really want the histogram you were expecting (i.e. heights correspond to fraction of counts, areas don't necessarily sum to 1), you can do this:
h <- hist(test,plot=FALSE)
h$counts <- h$counts/length(test)
plot(h)
Another possibility is to force the bar widths to be equal to 1.0, e.g.
hist(test,freq=FALSE,breaks=0:10)
Or maybe you want
plot(table(test)/length(test))
or
plot(table(test)/length(test),lwd=10,lend="butt")
? See also: How do you use hist to plot relative frequencies in R?