patchwork
patchwork copied to clipboard
Control order of legends inside plot_layout(guides = "collect")
I am trying to adjust the order of the guides in the legend. For instance, having the size guide below the color guide:
library(ggplot2)
library(patchwork)
p6 <- ggplot(mtcars) + geom_point(aes(mpg, disp, color=cyl, size = qsec))
p7 <- ggplot(mtcars) + geom_point(aes(mpg, hp, color=cyl, size = qsec))
(p6 + p7) +
plot_layout(guides='collect')

Created on 2022-03-18 by the reprex package (v2.0.1)
I tried something like this but to no avail:
(p6 + p7) +
plot_layout(guides='collect') +
guides(size = guide_legend(order = 1),
color = guide_legend(color = 2))

Created on 2022-03-18 by the reprex package (v2.0.1)
Thanks for any pointers!