如何在 R 中使用 `plot_grid` 减少一组图的一列图的图边距?

How to reduce plot margins of one column of plots of an arrange of plots using `plot_grid` in R?

我需要安排图表,其中每一行图表都有一个共同的图例。所有图的 y 和 x-axis 都使用相同的单位。下面我展示了我的地块排列方式:

我将每一行的共同图例提取为图表,然后将其作为附加列添加到我的排列中。

如您所见,带有图例 "consume" 的列在排列中有很多 space,我可以做些什么来减少它们的边距以支持其他两列?

我使用 plot_grid 是因为我看到 in this link 您可以使用 ggdraw.

创建常见的 x 和 y-axis 标题

您可以使用 plot_gridrel_widths 参数。这是一个可重现的例子:

library(ggplot2)
library(cowplot)
library(ggpubr)
theme_set(theme_cowplot())

df <- data.frame(x = 1:12, y = (1:12)^2)
df$grp = c('Some', 'Things', 'In a legend')

p <- ggplot(df, aes(x, y, color=grp)) + geom_point()
leg <- get_legend(p)
leg <- as_ggplot(leg)
p = p + theme(legend.position = "none")

plot_grid(
  p, p, leg, 
  p, p, leg,
  ncol = 3, rel_widths=c(2,2,1)
)