使用grid.arrange缩小和对齐图 [英] Shrink and Align plots with grid.arrange

查看:132
本文介绍了使用grid.arrange缩小和对齐图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三个图,我想将它们堆叠起来,缩小底部的2个,并确保它们垂直对齐.我可以做一个,但不能两个都做.如您在图1中所见,图是垂直对齐的,但是我需要缩小底部的两个图.在图2中,底部的两个已缩小,但未垂直对齐.

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?

这里是一个例子:

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

图2:

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

推荐答案

尝试使用 rel_heights 参数:

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

这篇关于使用grid.arrange缩小和对齐图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆