I'd like to center a common legend below two plots (see reprex below).
This does not seem to work atm (at least not how I thought it could work), and I somehow expect/fear that this is technically not possible?!?
library(tidyverse)
library(patchwork)
set.seed(17)
dat1<- tibble(x= rep(1:5,2),
y= sample(1:10,10,replace=T),
grp= rep(c("A","B"),each=5))
dat2<- tibble(x= rep(1:5,2),
y= sample(1:10,10,replace=T),
grp= rep(c("A","B"),each=5))
p1<- ggplot(dat1,aes(x,y)) + geom_line(aes(col=grp))
p2<- ggplot(dat2,aes(x,y)) + geom_line(aes(col=grp))
p1+p2+ plot_layout(guides="collect")
p3<- ggplot(dat1,aes(x,y)) + geom_line(aes(col=grp)) + theme(legend.position="bottom")
p4<- ggplot(dat2,aes(x,y)) + geom_line(aes(col=grp)) + theme(legend.position="bottom")
p3+p4+ plot_layout(guides="collect")

I'd like to center a common legend below two plots (see reprex below).
This does not seem to work atm (at least not how I thought it could work), and I somehow expect/fear that this is technically not possible?!?