我想在 ggplot2 中的分布条形图上添加一条线以显示平均分布,但遇到了麻烦。
像这样的 ggplot 调用:
ggplot(x, aes(date_received)) +
geom_histogram(aes(y = ..count..), binwidth=30) +
geom_density()
为我提供每 30 天观察值的直方图条,但密度线跟踪每一天的计数,如下所示(底部的静态数据来自geom_density
.
是否可以添加一个geom_density
图层覆盖一条线,该线将显示 30 天观察组计数的平均值,例如binwidth
in geom_histogram
.
任何帮助表示赞赏。
根据 Brian S. Diggs 的回答e-mail https://stat.ethz.ch/pipermail/r-help/2011-June/280588.html你应该乘以..count..
in geom_density(
) 的值binwidth=
in geom_histogram()
.
set.seed(123)
df<-data.frame(x=rnorm(1000,100,15))
ggplot(df,aes(x))+
geom_histogram(binwidth = 2.5)+
geom_density(aes(y=2.5 * ..count..))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)