I am using the patchwork
package in r to create panels of plots like:
panel<- (p1+ plot_spacer()+p2 + p3)+
plot_layout(ncol = 2) +
plot_layout(guides = "collect")
panel
I want to specify the legend to go to the empty top-right panel, more or less like this
Appreciate any pointers
For this use case patchwork
provides guide_area()
which could be used to place the legend:
library(patchwork)
library(ggplot2)
p1 <- p2 <- p3 <- ggplot(mtcars, aes(hp, mpg, color = factor(cyl))) +
geom_point()
p1 + guide_area() + p2 + p3 +
plot_layout(ncol = 2) +
plot_layout(guides = "collect")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With