Overlay normal density distribution using ggplot in R

I am trying to impose a normal distribution on 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?

+4
source share
1 answer

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))

Work!

+5
source

Source: https://habr.com/ru/post/1548057/


All Articles