本文介绍了ggarrange绘制列表中的所有图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多想将它们放在一页上的图,ggarrange在这方面做得很好,但是,似乎我必须将这些图的每一个都放在存储它们的列表中ggarrange函数的输入,而不是直接将列表作为输入,有关详细信息,请参见以下内容:

I have lots of plot that I want to put them on one page, ggarrange does a good work on this, however, it seems like I have to put each of those plots in the list in which they are stored as input of this ggarrange function, other than put the list as input directly, see following for details:

一个朴素的例子:

p1 <- ggplot(mtcars, aes(mpg, wt, colour = factor(cyl))) +
  geom_point()
p2 <- ggplot(mtcars, aes(mpg, wt, colour = factor(cyl))) +
  geom_point() + facet_wrap( ~ cyl, ncol=2, scales = "free") +
  guides(colour="none") +
  theme()
plot_list = list(p1,p2) 

我现在可以做什么:

ggarrange(p1,p2, widths = c(2,1), labels = c("a", "b"))

我真正想要但未能做到的事情:

What I really want but failed to do:

ggarrange(plot_list, widths = c(2,1), labels = c("a", "b"))

有人知道吗?如果地块数量很多,这可以节省大量时间,并且可能会不时更改.该示例不是我的示例,是从此处复制而来的.

Anyone know how? this could save a lot of time if the number of plots is large and may change from time to time.The sample is not mine, copied from here.

=======编辑=======

根据以下出色的答案,至少有一些可用的选项:1,查看已接受的答案,2,来自我删除的答案,修改不大do.call(ggarrange, c(plot_list[1:2], widths = c(2, 1), labels = c("a", "b")))为了将参数传递给函数ggarrangec()为我工作,但as.list()却没有.

According to the excellent answers below, there are at least to options available:1, See the accepted answer,2, Which is come from a deleted answer with little modification by medo.call(ggarrange, c(plot_list[1:2], widths = c(2, 1), labels = c("a", "b")))To pass argument to function ggarrange, c() worked for me but as.list() did not.

推荐答案

签出?ggarrange的帮助文件.它具有一个plotlist=参数.只需在此处传递您的列表即可.

Check out the help file for ?ggarrange. It has a plotlist= parameter. Just pass your list there.

ggarrange(plotlist=plot_list, widths = c(2,1), labels = c("a", "b"))

这篇关于ggarrange绘制列表中的所有图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 00:06