You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
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...".
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.
The text was updated successfully, but these errors were encountered: