-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Closed
Labels
Description
I have tried to use stat_function in combination with aes(group = ...) and args=list(...), taking into account the documentation
stat_function() understands the following aesthetics (required aesthetics are in bold):
- group
- y
of what I expected different curve plots depending on arguments taken from each group, but I only obtained one curve.
I have asked in stackoverflow if there is a way to do this, but further, I was looking for examples using these aesthetics combined with stat_function, and I did not find anything.
I copy my example of the link:
library(ggplot2)
mtcars$vs <- as.factor(mtcars$vs)
ggplot(mtcars,aes(x=mpg, fill = vs, colour = vs)) + geom_density(alpha = 0.1) +
stat_function(aes(group = vs), fun = dnorm, args = list(mean = mean(mtcars$mpg), sd = sd(mtcars$mpg)))
I have also tried deleting fill = vs, colour = vs, and changing it by group = vs, but no result. Since I have also not found any example, not even in the vignette ("ggplot2-specs"), I wonder if this really works.
Thank you!