grid.arrange using list of plots

前端 未结 1 1055
栀梦
栀梦 2020-12-15 23:11

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

         


        
相关标签:
1条回答
  • 2020-12-15 23:33

    You could use mget like this:

    plist2 <- mget(paste0("g", 1:4))
    do.call(grid.arrange, plist2)
    

    But it would be better to put the plots into a list when creating them, like this:

    funs <- c(sin, tan, cos)
    DF <- data.frame(x=c(0, 10))
    
    g <- lapply(funs, function(fun, df) {
      ggplot(df, aes(x)) + stat_function(fun=fun)
    }, df=DF)
    
    #g[[4]] <- tableGrob(data.frame(x = 1:10, y = 2:11, z = 3:12))
    #better for programmatic use:
    g <- c(g, list(tableGrob(data.frame(x = 1:10, y = 2:11, z = 3:12))))
    
    do.call(grid.arrange, g)
    
    0 讨论(0)
提交回复
热议问题