我用ggplot2创建了这个直方图:
x = rnorm(100,0,150)
df <- data.frame(val=c(x))
ggplot(df, aes(val,..density.., fill = ..x..>100)) +
geom_histogram(binwidth=bw.SJ(df$val), colour="black") +
scale_fill_hue(h=c(115,230))
我想将pdf添加到此直方图中,但是当添加下一行时:
geom_density(colour="red", lwd=1) +
这将返回错误:
Error in get(x, envir = this, inherits = inh)(this, ...) :
Aesthetics can not vary with a ribbon
提前致谢!
如果您指定fill = ..x..>100)
内部geom_histogram
而不是整个图,它应该可以工作。您不能在密度上改变填充颜色。
ggplot(df, aes(val)) +
geom_histogram(aes(fill = ..x.. > 100),
binwidth = bw.SJ(df$val), colour = "black") +
scale_fill_hue(h = c(115, 230)) +
geom_density(colour = "red", lwd = 1)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句