在ggplots列表上调用grid.arrange [英] calling grid.arrange on a list of ggplots

查看:65
本文介绍了在ggplots列表上调用grid.arrange的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题与此处的问题有关:

This question is linked to this one here:

相关帖子

我现在的问题是:在我的代码中,我通过调用lapply在列表中生成ggplots列表.我首先使用lapply,因为我执行了大量的类似ggplots,并且手动生成每个ggplots太麻烦了.如何概括我的代码?

My present question is: In my code I generate a list of ggplots in a list by calling lapply. I use lapply in the first place because I execute a fairly big amount of similar ggplots and it would be too cumbersome to generate each ggplots manually. how can I generalize my code?

p <- qplot(rnorm(30))

plist <- lapply(c(1:10),FUN=function(x){

  qplot(rnorm(30))

})

#works
year.plots <- list(p,p)
do.call(grid.arrange, c(year.plots))

#works
plist[[1]]

#works
grid.arrange(p,plist[[1]])

#does not work
year.plots <- list(p,plist[[1]])
do.call(grid.arrange, c(year.plots))

#How to generalize with the following idea?
year.plots <- list(p,plist[[1]],plist[[2]],...)
do.call(grid.arrange, c(year.plots))

推荐答案

使用gridExtra v> = 2.0.0,您现在可以这样做,

With gridExtra v>=2.0.0, you can now do,

grid.arrange(grobs = year.plots)

这篇关于在ggplots列表上调用grid.arrange的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆