Skip to content

Should legend.key inherit from panel.background? #5549

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
teunbrand opened this issue Nov 29, 2023 · 0 comments · Fixed by #5551
Closed

Should legend.key inherit from panel.background? #5549

teunbrand opened this issue Nov 29, 2023 · 0 comments · Fixed by #5551

Comments

@teunbrand
Copy link
Collaborator

One thing I often forget when I change the panel background is to also change the legend key accordingly.
I'd like to propose that the following code:

library(ggplot2)

ggplot(mpg, aes(displ, hwy)) +
  geom_point(aes(shape = factor(cyl))) +
  theme(
    panel.background = element_rect(fill = "cornsilk")
  )

Would produce the same plot as this:

ggplot(mpg, aes(displ, hwy)) +
  geom_point(aes(shape = factor(cyl))) +
  theme(
    panel.background = element_rect(fill = "cornsilk"),
    legend.key = element_rect(fill = "cornsilk")
  )

Created on 2023-11-29 with reprex v2.0.2

It would be a convenience if the legend key inherited from the panel background, to keep these in sync automatically.
To make this work as intended, the themes should probably omit the legend key definitions. These currently have a slightly different fill ("grey95") than the background ("grey92"), but I think the difference would be barely noticible to a human eye.

@teunbrand teunbrand changed the title Should legend.key inherit from plot.background? Should legend.key inherit from panel.background? Nov 29, 2023
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 a pull request may close this issue.

1 participant