Shrink and Align plots with grid.arrange

2019-09-03 08:26发布

I have three plots and I would like to stack them, shrink the bottom 2, and make sure they are vertically aligned. I can do one or the other, but not both. As you can see in plot 1, the plots are vertically aligned, but I need to shrink the bottom two; and in plot 2, the bottom two have been shrunk, but are not vertically aligned.

How can I shrink the bottom two plots and make sure all the plots are vertically aligned?

Here is an example:

ggplot:

library(gridExtra)
library(ggplot2)
library(cowplot)
a <- ggplot(data = diamonds, mapping = aes(y = carat, x = price)) + geom_line()
b <- ggplot(data = diamonds, mapping = aes(x = clarity)) + geom_bar()
c <- ggplot(data = diamonds, mapping = aes(x = color)) + geom_bar()

Plot 1:

plot_grid(a, b, c, labels=c("", "", ""), ncol = 1, nrow = 3, align = "v")

enter image description here

Plot 2:

grid.arrange(a,b,c, ncol = 1, nrow = 3, widths = c(1), heights = c(1,.3,.3))

enter image description here

标签: r ggplot2
1条回答
疯言疯语
2楼-- · 2019-09-03 08:33

Try the rel_heights argument:

plot_grid(a, b, c, ncol = 1, align = "v", rel_heights = c(3, 1, 1))
查看更多
登录 后发表回答