Histogram with weights in R

天大地大妈咪最大 提交于 2019-12-01 04:27:11

By default, geom_histogram() will use frequency rather than density on the y-axis. However, you can change this by setting your y aesthetic to ..density.. like so:

ggplot(foo, aes(x = v, y = ..density.., weight = w)) + geom_histogram()

This will produce a weighted histogram of v with density on the y-axis.

You can also do this with the freq argument in weighted.hist() from the plotrix package:

library(plotrix)
with(foo, weighted.hist(v, w, freq = FALSE))

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