Combine geom_function and geom_ribbon in ggplot2

51 views Asked by At

I would like to highlight the area between two function curves plotted with geom_function.

For example, I create two curves:

ggplot() + geom_function(fun = function(x){x^2}) + geom_function(fun = function(x){x^2 + 1})

How can I highlight the area between these curves? I think geom_ribbon might be the answer, but all the example code I saw for geom_ribbon used a dataset for mapping. How can I do that with geom_function, i.e. curves only based on a function and not on actual data?

0

There are 0 answers