-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple legends with position="inside" #5712
Comments
This is not possible at this time |
Should this be possible? I cannot think of a compelling use case on top of my head, or at least, more compelling than satisfying curiosity. |
Some time ago, I saw this issue in Stackoverflow: https://stackoverflow.com/questions/21798364/independently-move-2-legends-ggplot2-on-a-map |
I'm running into this as well. The documentation doesn't say anything about which components of theme are respected in |
I seem to be hitting either a related issue or another manifestation of this, though the use case is a bit different as it's a single legend per figure with multiple figures patchworked together. The deprecation warning tells you to use It's easy to read the the blog post as saying this isn't expected behavior: "To cover such cases, there is now a specialised |
I understand the confusion this may have caused and it should be made clearer in the documentation which theme elements are used in the legend itself versus which ones are used to compose the legend within the plot. With regards to positions; With regards to which theme elements guides respond to; ggplot2::guide_legend()$elements
#> $background
#> [1] "legend.background"
#>
#> $margin
#> [1] "legend.margin"
#>
#> $key
#> [1] "legend.key"
#>
#> $key_height
#> [1] "legend.key.height"
#>
#> $key_width
#> [1] "legend.key.width"
#>
#> $text
#> [1] "legend.text"
#>
#> $theme.title
#> [1] "legend.title"
#>
#> $spacing_x
#> [1] "legend.key.spacing.x"
#>
#> $spacing_y
#> [1] "legend.key.spacing.y"
#>
#> $text_position
#> [1] "legend.text.position"
#>
#> $title_position
#> [1] "legend.title.position"
#>
#> $byrow
#> [1] "legend.byrow" Created on 2024-05-31 with reprex v2.1.0 |
I am running into this issue as well. I have two legends I want to place inside my map and I want to control where I put each of them separately so they plot around the actual contents of the map. But it seems I can only control the location inside the plot for one legend separately with guides() or all legends together in theme(). The only workarounds seem to be creating the legends as separate objects and then plotting them together with the original ggplot with cowplot. Seems like a very inefficient way to do this. Is it really the only way? |
Currently, that is the only way I imagine. |
I have recently installed the
ggplot2
3.5.0 release, and after reading the new features added to the Legends Placement, I was very curious to know if it is possible to have multiple inside legends (position = "inside"
) at different positions by using the newlegend.position.inside
argument for each guide. For example,cty
legend at bottom-right andcyl
at top-right. However, it does not work.It seems only works by using the global theme’s
legend.position.inside
arguments, grouping both legends at the same position, but for now is not possible to not place them separately.The text was updated successfully, but these errors were encountered: