Superimpose a normal distribution to a density using ggplot in R
ggplot2, r
Solution
Following @aosmith advice:
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!
Problem
I am trying to superimpose a normal distribution to a density using ggplot in R: ``` 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?