【发布时间】:2022-01-05 16:22:17
【问题描述】:
以下代码生成如下图所示的网格:
library(tidyverse)
library(cowplot)
p1 <- cars %>%
ggplot(aes(x = speed, y = dist)) +
geom_point() +
theme_bw()
p2 <- cars %>%
ggplot(aes(x = speed, y = dist)) +
geom_point() +
scale_y_continuous(trans = "log2", breaks = c(2, 4, 8, 16, 32, 64, 128),
limits = c(2, 128)) +
annotation_logticks(sides = "l") +
theme_bw()
p3 <- diamonds %>%
ggplot(aes(x = carat, y = price, colour = clarity)) +
geom_point() +
theme_bw() +
theme(legend.position = c(0.8, 0.4))
p4 <- plot_grid(p1, p1, nrow = 2, labels = c("B", "C"))
p5 <- plot_grid(p3, p4, nrow = 2, align = "hv", axis = "lb", rel_heights = c(0.5, 1),
labels = c("A", ""))
p6 <- plot_grid(p1, p2, nrow = 2, align = "h", rel_heights = c(0.5, 1),
labels = c("D", "E"))
p7 <- plot_grid(p5, p6, ncol = 2, align = "b")
p7
我希望将(A)的底轴与(B,C)的顶轴分别对齐,并将(C)的底轴与(E)的底轴对齐。这应该在 (E) 的高度和 (A) 的宽度上拉伸 (B,C) 网格图。我尝试了几种对齐方式。
我发现queries 与此问题类似,它允许正确对齐宽度或高度,但不能同时对齐!
我还要补充一点,这个可重现的例子是我能得到的最接近我的实际情节的例子。在这里,我设法将宽度与面板 (A) 对齐,但无法将 (B,C) 的高度与 (E) 对齐。
【问题讨论】: