Skip to content

Allow justification of legends larger than the available space #4437

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

Merged
merged 4 commits into from
Apr 22, 2021

Conversation

thomasp85
Copy link
Member

Fix #3635

This PR aims to address the issue of correctly justifying legends if they are larger than the space available. It does so by setting the viewport size to the size of the legend...

re-rendering of the issue example to show it is working

library(ggplot2)
library(magrittr)

p <- iris %>%
  ggplot(
    aes(x = Sepal.Length, 
        y = Sepal.Width, 
        color = Petal.Length, 
        shape = Species, 
        fill = Petal.Width)
  ) + 
  geom_point() + 
  theme(legend.position = "bottom")

p + theme(legend.justification = "left")

p + theme(legend.justification = "right")

Created on 2021-04-20 by the reprex package (v2.0.0)

(@clauswilke I'm setting you as reviewer as I think you are the other person most familiar with the intricacies of grid. If you don't have time just let me know)

@thomasp85 thomasp85 added this to the ggplot2 3.3.4 milestone Apr 20, 2021
@thomasp85 thomasp85 requested a review from clauswilke April 20, 2021 09:03
@clauswilke
Copy link
Member

I should be able to review this afternoon.

* Fix a bug in legend justification where justification was lost of the legend
dimensions exceeded the available size (@thomasp85, #3635)

* Fix calculation of confidence interval for locfit smoothing (@topepo, #3806)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this meant to be part of the PR?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah - I forgot to ask for a news bullet in another PRR I merged and just thought I would fold it in here... If you feel this is too bad we can make a separate commit instead

@thomasp85 thomasp85 merged commit 333ae5c into master Apr 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

legend.justification not preserved when space is limited
2 participants