I feel I'm always asking a variation of the same question :(
I recently got a list of plots + table to display on grid.arrange using the do.call function
library(grid)
library(ggplot2)
library(gridExtra)
g1 <- ggplot(data.frame(x=c(0, 10)), aes(x)) + stat_function(fun=sin)
g2 <- ggplot(data.frame(x=c(0, 10)), aes(x)) + stat_function(fun=tan)
g3 <- ggplot(data.frame(x=c(0, 10)), aes(x)) + stat_function(fun=cos)
g4 <- tableGrob(data.frame(x <- 1:10, y<-2:11, z<-3:12))
plist <- list(g1,g2,g3,g4)
do.call("grid.arrange", c(plist))
This works but I need "plist" to be generated based on the variable "numruns"
I've tried this, but it does not work:
plist2 <- list(paste0("g", seq_len(numruns+1)))
do.call("grid.arrange", c(plist2))
I believe what I'm doing is calling grid.arrange("g1","g2", ...) rather than grid.arrange(g1,g2, ...).
I solved a similar problem before using lapply, but that doesn't seem to help me in this case, or else I'm using it incorrectly.
Thanks for any help.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…