简体   繁体   English

如何增加由grid.arrange生成的图的大小

[英]How to increase the size of a plot resulting from grid.arrange

I am working with R and Shiny to show different tables at once by using the packages ggplot2 and gridExtra. 我正在与R和Shiny一起使用包ggplot2和gridExtra来一次显示不同的表。

My problem is that, when I try to use gridExtra to merge 12 plots, they turn out to be tiny. 我的问题是,当我尝试使用gridExtra合并12个地块时,它们却很小。

The code I have for the merging is the following: 我要合并的代码如下:

grid.arrange(p1, p12, p2, p22, p3, p32, p4, p42, p5, p52, p6, p62,
             ncol=2)

And this is how all plots are coded: 这是所有图的编码方式:

p62 = ggplot(data = dataframe1, aes(x = Week, y = DB, con = Type)) +
  xlab("Week") +
  ggtitle("Country") +
  theme(plot.title = element_text(size = 10, face = "italic")) +
  ylab("DB") +
  geom_line(size = 1) +
  geom_line(aes(colour = Type), size = 1) + 
  guides(col = guide_legend(title = "Period")) + 
  scale_color_manual(values = c('#999999', '#E69F00', "purple"))

When I test it using only 4 plots, the size of the individual plots is perfect: 当我仅使用4个图进行测试时,单个图的大小是完美的:

地块大小只有4个地块

But when I write all 12, they become tiny: 但是当我写下全部12时,它们变得很小了:

所有12个地块的地块大小

My question is then: Is there a way to change the size of the individual plots? 那么我的问题是:是否有办法改变单个地块的面积?

There are multiple parts to this answer: 此答案包含多个部分:

In Shiny, to increase the size (height) or a plot output, use the height argument in the output element in your UI: 在Shiny中,要增加大小(高度)或打印输出,请在UI的output元素中使用height参数:

plotOutput(outputId, height = "400px")

Next, as @Tung suggested, you don't have to plot all redundant legends. 接下来,按照@Tung的建议,您不必绘制所有多余的图例。 See grid_arrange_shared_legend in the package lemon , and perhaps g_legend . grid_arrange_shared_legend在包lemon ,也许g_legend

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM