grid - 使用 grid.arrange 为使用 gridExtra::grid.arrange 制作的多个图添加标题

标签 grid gridextra

我必须使用 gridExtra::grid.arrange 来绘制除彼此之外的多个图,因为我使用该包来创建图的拟合。
我必须使用 grid.arrange 为绘图创建一个标题。
现在我想将两者结合起来,但不知道如何结合。所以:我想绘制几个图形,并给它们一个不同的标题。

我有 euler1 和 euler2 适合 tat 在欧拉图中代表我的数据。
为了绘制除海誓山盟之外的 2 个图,此代码对我有用:

gridExtra::grid.arrange(plot(euler1),plot(euler2))

为了给一个单一的情节一个标题,这个代码对我有用:
plot1 <- plot(euler1)
grid.arrange(grobs = list(plot1), top = "Title 1")

现在,我想结合这两个代码。
我该怎么做?

我尝试例如(但不起作用):
plot1 <- plot(euler1)
plot2 <- plot(euler2)
gridExtra::grid.arrange(plot1, plot2, grobs = list(plot1, plot2), top = list("Title 1","Title 2"))

亲切的问候,
朱迪思

最佳答案

通常你会为情节本身添加标题,如

p1 = ggplot() + ggtitle('plot 1')
p2 = ggplot() + ggtitle('plot 2')

grid.arrange(grobs = list(p1, p2), top = "Global Title", ncol=2)

但如果你更喜欢使用 grid.arrange 的 top标题的参数,你可以嵌套它们,
p = ggplot()
grid.arrange(arrangeGrob(p, top = 'title 1'), arrangeGrob(p, top = 'title 2'), top = "Global Title", ncol=2)

关于grid - 使用 grid.arrange 为使用 gridExtra::grid.arrange 制作的多个图添加标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53340828/

相关文章:

css - 如何创建网格/平铺 View ?

r - 如何在 R 中为 tableGrob 自定义特定列?

r - 使 ggplot 的 strip 文本延伸到轴文本上

r - 控制R markdown中ggplot循环生成的每个pdf页面的图形大小和数量

magento - Magento 网格列中数据库的时间戳值

button - 通过代码动态生成按钮

r - 将注释框添加到 ggplot 对象的网格

r - 在 R 中使用 gridextra 时,向 tableGrob 添加多行脚注

java - 无法使测试方法与 Selenium 网格并行运行

algorithm - 回答大网格矩形查询中的元素总和