dupont
另外如果是ggplot的多图组合的话,推荐patchwork
你的要求就是4个图共享一个图例对吧:
library(patchwork)
library(ggplot2)
library(ggplot2)
p1 <- ggplot(mtcars) +
geom_point(aes(mpg, disp)) +
ggtitle('Plot 1')
p2 <- ggplot(mtcars) +
geom_boxplot(aes(gear, disp, group = gear)) +
ggtitle('Plot 2')
p3 <- ggplot(mtcars) +
geom_point(aes(hp, wt, colour = mpg)) +
ggtitle('Plot 3')
p4 <- ggplot(mtcars) +
geom_bar(aes(gear)) +
facet_wrap(~cyl) +
ggtitle('Plot 4')
p1 + p2 + p3 + p4 +
plot_layout(guides = 'collect')

<sup>Created on 2020-05-05 by the reprex package (v0.3.0.9000)</sup>