I'm trying to create a utility function that combines several geom_
, like in this example (which doesn't work):
my_geom_y <- function(yy, colour){
geom_line(aes(y=yy), col=colour) + geom_point(aes(y=yy), col=colour)
}
so that then I can do this:
myX <- 0:90
ggplot(mapping = aes(x=myX)) + my_geom_y(dlnorm(myX), "red") + my_geom_y(dexp(myX), "blue")
Is that possible?
I tried using get()
, eval()
, substitute()
, as.name()
with no avail.
Looking at related posts: passing parameters to ggplot, Use of ggplot() within another function in R didn't help.