Closed as not planned
Closed as not planned
Description
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.