Simple histogram plot wrong?

僤鯓⒐⒋嵵緔 提交于 2019-12-02 04:46:13
Ben Bolker

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?

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!