Description
I would like to create a graph with the normal function from x=-2 to x=2 filled red under the curve from -2 to 0 and blue from 0 to 2.
I've tried
ggplot(NULL,aes(x=c(-2,2))) + geom_area(aes(x=c(-2,0)),stat="function", fun=dnorm, fill="red") +
geom_area(aes(x=c(0,2)),stat="function", fun=dnorm, fill="blue")
But it doesn't work as expected.
I know I could do it creating a x vector and a y vector of points and later using subset....
but how can I achieve it with the "stat" option?
I think it doesn't work, when you add a new area it doesn't respect whatever you did before.
I've also tried with the xmin and xmax option, without success.
It would also be nice to be able to specify two stat functions o values, one for ymax one for ymin, in order to easily paint the are between two curves.
Regards.