Использование пакета ggpubr
:
library(ggpubr)
# Simulating groups
mpg$Group <- "A"
mpg[mpg$class %in% unique(mpg$class)[1:3], "Group"] <- "B"
# Generating plots by group
for (grp in unique(mpg$Group)) {
assign(paste0("plot", grp),
ggplot(subset(mpg, Group == grp), aes(displ, hwy)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE) +
scale_y_continuous(position = "righ") +
theme_bw() +
facet_wrap(~ class, nrow = 1, scales = "free")
)
}
# Arranging plots with annotation
ggarrange(annotate_figure(plotA, left = "Group A"),
annotate_figure(plotB, left = "Group B"),
nrow = 2, align = "h")
Также проверьте параметр labels = "AUTO"
в ggarrange.