Repository navigation
collect guides when legend.position="bottom" #136
Description
Activity
You just need to make sure that the theming of the patchwork has
legend.position = 'bottom'as well. This can be done using either thethemeargument inplot_annotation(), or by&a theme object to it which will apply the theme to both the patchwork as well as to all subplots:p1 + p2 + plot_layout(guides = "collect") & theme(legend.position = 'bottom')
Reacted by David Schoch, Lluís Revilla, Rubem Dornas, Gorka Navarrete, Mark, Michał Krassowski, Mike Jay, Desmond Choy, Tyson Barrett, quanquan and 67 moreReacted by Antonio Alvarez, Beatriz Milz, Max Blasdel, Vilmar Benetti Filho, bersco, Thomas Bradley and Douglas LawtonReacted by B. Arman Aksoy, John-Henry Pezzuto, Beatriz Milz, Evan Muzzall, Lucas, Beka Stiling, Merritt Khaipho-Burch, Richard Abdill, Vilmar Benetti Filho, Daniel Malone and 9 moreReacted by Thomas Bradley and Douglas LawtonThis helped so much. If you write the code as
+ themeinstead of& theme, the legend position will not go where it is specified. The&is key.Reacted by Floris Vanderhaeghe, Rafael Charris, Sebastian Hacker and Chrysanthi PachoulideReacted by Silvia Talavera MarcosReacted by MH Manuel Haqiqatkhah, Elizabeth Pankratz and f-ferraroAwesome! Might be worth emphasizing this point in the (great) online manual on
plot_layout. As a newcomer, I came into the exact same issue.Thanks!
Reacted by Tyson Barrettis the manual position of the legend still not possible?
Reacted by tomlangbehnHi Thomas,
It seems like
guides=collectmight not be working anymore? I'm re-running the reprex from the first post and I'm getting the same legend twice. However, the position is still working.Thanks!
Melissa
Reacted by Eric R. Scott and Nicolás X. Gómez AndújarHi Melissa @melissagwolf,
Are you using R 4.0.0 ? This is a know bug #170 (Unless your session Information says something different)
Lluís
Reacted by Eric R. Scott and Sam ZipperYep, using 4.0.0. Thank you for the quick response!
This helped so much. If you write the code as
+ themeinstead of& theme, the legend position will not go where it is specified. The&is key.Thank. you. so. much. you are a godsend
Reacted by Melissa WolfYou just need to make sure that the theming of the patchwork has
legend.position = 'bottom'as well. This can be done using either thethemeargument inplot_annotation(), or by&a theme object to it which will apply the theme to both the patchwork as well as to all subplots:p1 + p2 + plot_layout(guides = "collect") & theme(legend.position = 'bottom')
What if I don't want to apply the theme to all the subplots?
In other words, I want to have the "collected" legend at the centre bottom of the first two plots, but not for the third one in the first line:
(((p1|p2) + plot_layout(guides = "collect") & theme(legend.position = "bottom"))|p2 + plot_layout(guides = "keep"))/(p1|p2)I cannot manage to have this working. any solution?
I cannot manage to have this working. any solution?
yup, this is pretty bad when including ggraph or circular visualisation which greatly benefit from
theme_void()while other panels are using non-void themes. One thing I tried was manually specifyingguide_area()but this did not work because the legend box was in always in vertical orientation (ignoringlegend.box='horizontal').What if I don't want to apply the theme to all the subplots? In other words, I want to have the "collected" legend at the centre bottom of the first two plots, but not for the third one in the first line:
(((p1|p2) + plot_layout(guides = "collect") & theme(legend.position = "bottom"))|p2 + plot_layout(guides = "keep"))/(p1|p2)I cannot manage to have this working. any solution?
@costavale In my case, I found two options, one not very fancy, but working and also a downgrading option. So, you can
- use
plot_annotation()like this:
p1 + p2 + plot_layout(ncol = 2, guides = "collect") +
plot_annotation(theme = theme_minimal() +
theme(legend.position = "bottom"))or
- downgrade ggplot2 from 4.x.x to 3.5.2 and run again, this seems to fix the conflict with patchwork
- use
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?!?