patchwork icon indicating copy to clipboard operation
patchwork copied to clipboard

Control order of legends inside plot_layout(guides = "collect")

Open DominiqueMakowski opened this issue 3 years ago • 0 comments

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!

DominiqueMakowski avatar Mar 18 '22 07:03 DominiqueMakowski