You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何对齐gtable与常规ggplot对象的Y轴?

问题:ggplot多图堆叠时Y轴对齐及视觉冗余优化

我尝试使用ggplot堆叠三张图表,其中上方两张包含两行Y轴标签,底部图表仅一行。实际场景中上方两图存在共性,希望减少视觉冗余。

我采用如下方法,但始终无法实现Y轴对齐。若有更合适的命令或包,欢迎推荐!我不局限于当前使用的包。

library(ggplot2); library(grid); library(gridExtra)

d <- mtcars

a <- ggplot(d[d$cyl==4,], aes(x=wt, y=mpg))+
  geom_point()

b <- ggplot(d[d$cyl==6,], aes(x=wt, y=mpg))+
  geom_point()

c <- ggplot(d, aes(x=qsec, y=mpg))+
geom_point()

topTwo <-plot_grid(a, b, ncol = 1, align = "v")
y.grob <- textGrob("some label for top two", gp=gpar(), rot=90)

topTwo <- grid.arrange(arrangeGrob(topTwo, left = y.grob))

plot_grid(topTwo, c, ncol = 1, align='v',axis='lr', rel_heights = c(100,50))

Y轴未对齐

内容的提问来源于stack exchange,提问作者Ryan Utz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.18 02:19:56