Skip to content

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

Closed
@teunbrand

Description

@teunbrand

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions