使用grid.arrange缩小和对齐绘图

时间:2016-01-29 18:50:41

标签: r ggplot2

我有三个图,我想堆叠它们,收缩底部2,并确保它们垂直对齐。我可以做其中一个,但不能两个都做。正如你在图1中看到的那样,图是垂直对齐的,但我需要缩小底部两个;在图2中,底部两个已经缩小,但没有垂直对齐。

如何缩小底部的两个图并确保所有图都垂直对齐?

以下是一个例子:

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()

剧情1:

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

enter image description here

剧情2:

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

enter image description here

1 个答案:

答案 0 :(得分:3)

尝试rel_heights参数:

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