One really cool feature from the ggplot2 package, which I never used enough, added layer lists to the plot. The most interesting thing is that I can pass the list of layers as an argument to the function and add them to the plot. Then I could get the desired kind of plot, without necessarily returning the plot from the function (whether this is a good idea, another thing, but it was possible).
library(ggplot2) x <- ggplot(mtcars, aes(x = qsec, y = mpg)) layers <- list(geom_point(), geom_line(), xlab("Quarter Mile Time"), ylab("Fuel Efficiency")) x + layers
Is there any way to do this with pipes? Something similar to:
r ggplot2 dplyr magrittr
Benjamin
source share