[英]Superimpose a normal distribution to a density using ggplot in R
I am trying to superimpose a normal distribution to a density using ggplot in R: 我正在尝试使用R中的ggplot将正态分布叠加到密度:
ggplot(Data, aes(x=Rel, y=..density..)) +
geom_density(aes(fill=factor(cut)), position="stack") +
stat_function(fun = dnorm, args = list(mean = Rel.mean, sd = Rel.sd))
But I keep getting this error: 但我一直收到这个错误:
Error in eval(expr, envir, enclos) : object 'density' not found
Calls: print ... <Anonymous> -> as.data.frame -> lapply -> FUN -> eval
Why? 为什么? Any solution?
有解决方案吗
Following @aosmith advice: 关注@aosmith建议:
ggplot(Data, aes(x=Rel)) +
geom_density(aes(y=..density.., fill=factor(cut)), position="stack") +
stat_function(fun = dnorm, args = list(mean = Rel.mean, sd = Rel.sd))
Works! 作品!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.