I am using patchwork
to create a combined plot with a common legend that is centered on the top.
library(ggplot2)
library(patchwork)
x1 <- ggplot(iris,aes(Sepal.Width, Petal.Length, col=Species))+
geom_point()
x2 <- ggplot(iris,aes(Petal.Width, Petal.Length, col=Species))+
stat_ellipse(show.legend=F)
wrap_plots(x1, x2, guides="collect") +
theme(legend.position="top",
legend.direction="horizontal")
This is what I get.

This is what I was expecting.
ggpubr::ggarrange(x1, x2, common.legend=T)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…