我有 16 个地块 (4x4) 的排列。该排列的最后一列是图例,每行都通用。我在下面添加了一个假代码来创建与我所拥有的类似的东西:
library(ggplot2)
library(cowplot)
library(ggpubr)
theme_set(theme_cowplot())
df1 <- data.frame(x = 1:12, y = (1:12)^2)
df1$grp = c('A', 'B', 'C')
df2 <- data.frame(x = 1:12, y = (1:12)^2)
df2$grp = c('D', 'E')
df3 <- data.frame(x = 1:12, y = (1:12)^2)
df3$grp = c('F', 'G', 'H','I')
df4 <- data.frame(x = 1:12, y = (1:12)^2)
df4$grp = c('J', 'K')
p1 <- ggplot(df1, aes(x, y, color=grp)) + geom_point()
leg1 <- get_legend(p1)
leg1 <- as_ggplot(leg1)
p1 = p1 + theme(legend.position = "none",axis.title.x =element_blank(),axis.title.y =element_blank())
p2 <- ggplot(df2, aes(x, y, color=grp)) + geom_point()
leg2 <- get_legend(p2)
leg2 <- as_ggplot(leg2)
p2 = p2 + theme(legend.position = "none",axis.title.x =element_blank(),axis.title.y =element_blank())
p3 <- ggplot(df3, aes(x, y, color=grp)) + geom_point()
leg3 <- get_legend(p3)
leg3 <- as_ggplot(leg3)
p3 = p3 + theme(legend.position = "none",axis.title.x =element_blank(),axis.title.y =element_blank())
p4 <- ggplot(df4, aes(x, y, color=grp)) + geom_point()
leg4 <- get_legend(p4)
leg4 <- as_ggplot(leg4)
p4 = p4 + theme(legend.position = "none",axis.title.x =element_blank(),axis.title.y =element_blank())
plot_grid(
p1, p1, p1, leg1,
p2, p2, p2, leg2,
p3, p3, p3, leg3,
p4, p4, p4, leg4,
ncol = 4, rel_widths=c(2,2,2,0.5),align = "hv"
)
所有绘图共享相同的 Y 轴和 X 轴单位,因此我想为 x 轴创建一个标签(X
) 和 y 轴的一个标签 (y
)。此外,我还想为我的排列的前三列(从左到右)添加一个标签(第一列:Column1
,第二列:Column2
,第 3 校:Column3
).
有谁知道该怎么做?