【发布时间】:2014-07-11 11:20:39
【问题描述】:
我正在尝试使用 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))
但我不断收到此错误:
Error in eval(expr, envir, enclos) : object 'density' not found
Calls: print ... <Anonymous> -> as.data.frame -> lapply -> FUN -> eval
为什么?有什么解决办法吗?
【问题讨论】:
-
如果您提供一个小的reproducible example,您将更容易得到答案
-
在this question 上查看 cmets。该错误可能是因为您设置了全局 y 而不是在
geom_density中设置 y。 -
没有数据和 MWE,这个问题没有用。