Skip to content

Legend spacing #5283

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

Closed
wants to merge 2 commits into from
Closed

Legend spacing #5283

wants to merge 2 commits into from

Conversation

teunbrand
Copy link
Collaborator

@teunbrand teunbrand commented Apr 24, 2023

This PR aims to fix #4352 and fix #4977 and entails a visual change.

To recap the issue: whether the legend.spacing.{x/y} was adhered to between keys was strangely dependent on the guide_legend(byrow = ...) setting. This made setting vertical spacing very unintuitive. With guides having been recently rewritten, there is no better time to justify visual changes.

This PR currently does three things:

  • The legend.spacing.{x/y} inherits from the legend.spacing theme setting.
  • The effect of byrow on spacing is nullified.
  • It discriminates the text-to-something spacing, from key spacing.

There are a few things I'd like some input on:

  • Should we expose the text-to-something spacing to users, as a legend.spacing.text theme setting? Note that for finetuning text-to-something spacing, the margin argument is available.
  • Under defaults, the proposed change is aggressively noticeable. Should we change some theme settings to come closer to the previous plots?

This PR breaks a bunch of visual tests, so I've not committed these changes yet in anticipation of further changes.

A visual example of the new spacing:

devtools::load_all("~/packages/ggplot2/")
#> ℹ Loading ggplot2

p <- ggplot(mpg, aes(displ, hwy)) +
  geom_point(aes(colour = class)) +
  guides(colour = guide_legend(ncol = 2))
p

Removing the spacing brings the plot closer to previous plots.

p + theme(legend.spacing.y = unit(0, "pt"))

Created on 2023-04-24 with reprex v2.0.2

@teunbrand teunbrand added the visual change 👩‍🎨 Rendering change that will affect look of output label Apr 24, 2023
@thomasp85 thomasp85 self-requested a review September 12, 2023 09:17
Copy link
Member

@thomasp85 thomasp85 left a comment

Choose a reason for hiding this comment

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

We should definitely not introduce such a major visual change, so while the intent of the PR is good, we should bring the default behaviour back in line with the current.

As for exposing the "text" gap I'm in general against because it seems like a difficult thing to teach users, but if you can make a motivated example of where it may be needed please show it

@teunbrand teunbrand mentioned this pull request Oct 5, 2023
@teunbrand
Copy link
Collaborator Author

Closing this in favour of #5456

@teunbrand teunbrand closed this Nov 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
visual change 👩‍🎨 Rendering change that will affect look of output
Projects
None yet
Development

Successfully merging this pull request may close these issues.

legend.spacing.{x/y} is not inherited in guide_legend(). guide_legend ignores legend.spacing.(x/y) depending on byrow
2 participants