另一种选择是使用textGrob 为常见的 x 和 y 标签添加注释。
在此示例中,如果您希望删除单个轴标签,只需在绘图调用中包含 theme(axis.title = element_blank())。 (或者,对于 y 轴,使用 theme(axis.title.y=element_blank()))。
library(ggplot2)
library(cowplot)
library(grid)
library(gridExtra)
ToothGrowth$dose <- as.factor(ToothGrowth$dose)
#make 4 plots
p1<-ggplot(ToothGrowth, aes(x=dose, y=len)) +
geom_boxplot()
p2<-ggplot(ToothGrowth, aes(x=dose, y=supp)) +
geom_boxplot()
p3<-ggplot(ToothGrowth, aes(x=supp, y=len)) +
geom_boxplot()
p4<-ggplot(ToothGrowth, aes(x=supp, y=dose)) +
geom_boxplot()
#combine using cowplot
plot<-plot_grid(p1, p2, p3, p4, align='vh', vjust=1, scale = 1)
#create common x and y labels
y.grob <- textGrob("Common Y",
gp=gpar(fontface="bold", col="blue", fontsize=15), rot=90)
x.grob <- textGrob("Common X",
gp=gpar(fontface="bold", col="blue", fontsize=15))
#add to plot
grid.arrange(arrangeGrob(plot, left = y.grob, bottom = x.grob))