Reputation: 405
I would like to generalize my function calls to be able to pass these calls to a second function as parameters.
In my case I have mutliple ggplots that I store as a list for example:
year.plots <- lapply(c("2008","2009","2010","2011","2012","2013","2014"),
FUN=function(x){
ggplot(data=french.temp.load[french.temp.load$Year==x,],
aes(x=Temperature_K,y=load,color=Month)) +
geom_point(alpha=0.5)
})
Now I would like to passe them to grid.arrange. Is it possible to do something like this?
grid.arrange(seq(year.plots),ncol=3)
Thanks
Upvotes: 2
Views: 188
Reputation: 61983
I think this is what you want. It's hard to be sure since I don't use grid stuff often and you didn't provide a reproducible example.
# Make example data
p <- qplot(rnorm(30))
year.plots <- list(p, p, p, p, p, p, p)
# This will basically construct the call
# grid.arrange(p, p, p, p, p, p, p, ncol = 3)
do.call(grid.arrange, c(year.plots, ncol = 3))
Upvotes: 1