Skip to content

Feature request: warning for fill/colour mismatch between aes() and scale...() #3743

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
petyaracz opened this issue Jan 18, 2020 · 1 comment
Labels
feature a feature request or enhancement scales 🐍

Comments

@petyaracz
Copy link

Custom legends are sensitive to whether it's a "fill" or "colour" aes. Switching between one and the other with essentially the same data is common.

Currently, if you forget to change e.g. "colour" to "fill" for your custom legend / colour scheme, ggplot2 ignores your colour scale / custom legend (since the "colour" aes is not specified) and uses the default for the colours / legend (since no information is provided for the "fill" aes).

Below, p1 uses "colour". p2 uses "fill" but the user forgot to update "scale_colour...".

library(ggplot2)
library(RColorBrewer)

p1 = ggplot(iris, aes(x = Species, y = Sepal.Length, colour = Species)) +
  geom_boxplot() +
  scale_colour_brewer(
    name = 'Dude which plant',
    palette = 'Set2'
    )

p2 = ggplot(iris, aes(x = Species, y = Sepal.Length, fill = Species)) +
  geom_boxplot() +
  scale_colour_brewer(
    name = 'Dude which plant',
    palette = 'Set2'
    )

p2 uses default legend and colour scheme without telling the user.

For p2, it might be useful to have a warning saying "you used scale_colour but didn't specify a colour aesthetic." or something like that.

May be related to #2691 / #2239.

@teunbrand
Copy link
Collaborator

I've tried implementing this and there are too many edge cases. For posterity, one such edge case is where e.g. fill spawns from a stat instead of being mapped by a user. The fill has no formal mapping, but does require a scale, so we have a scale without a mapping that shouldn't be warned about. Catching all these edge cases will unreasonably complicate the code, and that is why I'll be closing this issue as something that we won't fix.

@teunbrand teunbrand closed this as not planned Won't fix, can't repro, duplicate, stale Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement scales 🐍
Projects
None yet
3 participants