-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Setting options(ggplot2.discrete.fill)
overrides for aes(colour) with bad colourmap
#4149
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
Comments
Thanks, confirmed. Overriding is for convenience and it works perfectly when a vector of colors is supplied (or specifying library(ggplot2)
p <- ggplot(mpg, aes(class)) + geom_bar(aes(fill = drv))
# Correct, and works as expected
withr::with_options(
list(ggplot2.discrete.fill = function() scale_fill_viridis_d()),
print(p)
) # Incorrect, and fails with a cryptic error
withr::with_options(
list(ggplot2.discrete.fill = function() scale_colour_viridis_d()),
print(p)
)
#> Error: Unknown colour name: f |
@yutannihilation do you have any thoughts on how to best approach this? |
I was thinking if it's possible to check scale_colour_discrete <- function(..., type = getOption("ggplot2.discrete.colour", getOption("ggplot2.discrete.fill"))) {
# TODO: eventually `type` should default to a set of colour-blind safe color codes (e.g. Okabe-Ito)
type <- type %||% scale_colour_hue
if (is.function(type)) {
scale <- type(...)
if (!"colour" %in% scale$aesthetics) {
warn("...some nice warning...")
scale$aesthetics <- c(scale$aesthetics, "colour")
}
scale
} else {
scale_colour_qualitative(..., type = type)
}
} |
@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 |
@thomasp85 pretty sure I set both of them directly, so feel free to separate them |
Uh oh!
There was an error while loading. Please reload this page.
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 forcolour
(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).I'm running ggplot 3.3.2 in R 3.6.3 on a machine running ubuntu 18.04 LTS.
The text was updated successfully, but these errors were encountered: