在 ggarrange 中使用 common x-axes 堆叠时如何保留绘图大小?

How to preserve plot sizes when stacking with common x-axes in ggarrange?

我正在尝试在 ggplot 中使用常见的 x- 和 y-axes 堆叠绘图。我想要做的是只让底图显示 x-axis 标签和标题。但是我一直无法弄清楚如何在 ggplot2 中干净利落地做到这一点,而不会因为承载 x-axis labels/title 的优点而压扁底部图。 一定 有一个简单的方法来做到这一点——每个人都想堆叠图表,对吧?!

我目前正在尝试使用 ggarrange。下面的示例代码。请注意,底部图被垂直压缩,因为它具有刻度和轴标签。我可以只让前两个使用白色字体 labels/title,但是如果你使用那个 hack,则三个之间的边距 space 不合适。

我肯定对 gpubr 以外的软件包持开放态度,但我希望有一些不太复杂的东西可以在后续情况下使用,因为我相信我会再次遇到这种情况...

求助!! -瑞安

#
require(ggplot2); require(ggpubr)

X=data.frame(seq(as.Date("2001-01-01"),as.Date("2001-12-31"),by='days')); colnames(X)='date'
X$Y1=sample(80:100,size=nrow(X),replace=T)
X$Y2=sample(100:120,size=nrow(X),replace=T)
X$Y3=sample(50:70,size=nrow(X),replace=T)

plot.Y1= ggplot(X, aes(x=date,y=Y1))+
  geom_line()+lims(y=c(50,150))+
  theme(axis.title.x = element_blank(),axis.text.x=element_blank())

plot.Y2= ggplot(X, aes(x=date,y=Y2))+
  geom_line()+lims(y=c(50,150))+
  theme(axis.title.x = element_blank(),axis.text.x=element_blank())

plot.Y3= ggplot(X, aes(x=date,y=Y3))+
  geom_line()+lims(y=c(50,150))

x11(10,8)

ggarrange(plot.Y1,plot.Y2,plot.Y3,nrow=3,ncol=1)

Bottom plot is squished!

试试这个,

egg::ggarrange(plot.Y1,plot.Y2,plot.Y3,ncol=1)