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
{{ message }}
Repository navigation
Setting options(ggplot2.discrete.fill) overrides for aes(colour) with bad colourmap #4149
I know the option to set colour palette is in its early stages, so wanted to flag an error I noticed.
Looks like setting ggplot2.discrete.fill overwrites the colourmap for colour (which should be unchanged based on the documentation?) with a cmap that is both ugly and unintelligible (and it hides the legend too for some reason).
``` r
library(ggplot2)
(p1= ggplot(mpg, aes(class)) + geom_bar(aes(fill=drv)))
Thanks, confirmed. Overriding is for convenience and it works perfectly when a vector of colors is supplied (or specifying aesthetics = c("colour", "fill") in the scale function. But, it also leads us to unexpected behaviours like the one you encountered. here's another bad example. I agree this needs to be improved somehow.
library(ggplot2)
p<- ggplot(mpg, aes(class)) + geom_bar(aes(fill=drv))
# Correct, and works as expectedwithr::with_options(
list(ggplot2.discrete.fill=function() scale_fill_viridis_d()),
print(p)
)
# Incorrect, and fails with a cryptic errorwithr::with_options(
list(ggplot2.discrete.fill=function() scale_colour_viridis_d()),
print(p)
)
#> Error: Unknown colour name: f
@cpsievert are you relying on the colour->fill (or reverse) fallback in your theming packages? I'm very tempted to remove it to get it in line with how defaults are handled for continuous scales
Activity
yutannihilation commentedon Jul 28, 2020
Thanks, confirmed. Overriding is for convenience and it works perfectly when a vector of colors is supplied (or specifying
aesthetics = c("colour", "fill")in the scale function. But, it also leads us to unexpected behaviours like the one you encountered. here's another bad example. I agree this needs to be improved somehow.thomasp85 commentedon Apr 27, 2021
@yutannihilation do you have any thoughts on how to best approach this?
yutannihilation commentedon Apr 27, 2021
I was thinking if it's possible to check
aestheticsof the scale and tweak it (with some warning). For example:thomasp85 commentedon May 6, 2021
@cpsievert are you relying on the colour->fill (or reverse) fallback in your theming packages? I'm very tempted to remove it to get it in line with how defaults are handled for continuous scales
cpsievert commentedon May 6, 2021
@thomasp85 pretty sure I set both of them directly, so feel free to separate them