Skip to content

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

Closed as not planned
@petyaracz

Description

@petyaracz

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions