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
scale_[fill/color]_discrete currently default to scale_[fill/color]_hue. While this is a great default when there are a large number of levels to encode, it's not a great default there are just a few (i.e., it's not colour-blind safe or aesthetically pleasing compared to carefully chosen qualitative palettes like colorbrewer or Okabe-Ito). In the event there isn't already a "blessed" ggplot2 scale (e.g., scale_colour_brewer()), the usual way to override the default is with a custom qualitative colorscale is to use scale_[fill/color]_manual(), but this also isn't ideal for situations where you don't want to make any assumptions about the number of levels to encode (i.e., scale_[fill/color]_manual() errors if there are more levels than color codes).
I'd like to propose that scale_[fill/color]_discrete gain a new argument, say codes, that would accept a vector of color codes. In the event codes is longer than the number of levels to encode, it would effectively be scale_[fill/color]_manual; otherwise, it would effectively be scale_[fill/color]_hue. Moreover, I think it would make sense for codes to default to something sensible like Okabe-Ito.
It seems the implementation for this would be relatively straight-forward (see here for a proof-of-concept). If there's interest in pursuing this idea, I'd be happy to start a PR.
Hmmm, I think I'd prefer to take the same approach as scale_colour_gradient(), i.e. making the default type a parameter that you could set. And then we'd also provide a colour scale that was colour blind friendly by default.
As discussed here, if we make this part of ggplot2 3.3.1 we shouldn't change the default color scales. Also, I'm not sure if @hadley's comment #3826 (comment) has been addressed in the PR.
Activity
Add codes argument to scale_[fill/colour]_discrete(), closes tidyvers…
Add codes argument to scale_[fill/colour]_discrete(), closes tidyvers…
hadley commentedon Feb 21, 2020
Hmmm, I think I'd prefer to take the same approach as
scale_colour_gradient(), i.e. making the default type a parameter that you could set. And then we'd also provide a colour scale that was colour blind friendly by default.cpsievert commentedon Feb 22, 2020
Yea, so something like
codes = getOption("ggplot2.discrete.colour", default = "Okabe-Ito")?hadley commentedon Feb 22, 2020
I was thinking of a scale function
Add codes argument to scale_[fill/colour]_discrete(), closes tidyvers…
Add codes argument to scale_[fill/colour]_discrete(), closes tidyvers…
clauswilke commentedon Apr 29, 2020
As discussed here, if we make this part of ggplot2 3.3.1 we shouldn't change the default color scales. Also, I'm not sure if @hadley's comment #3826 (comment) has been addressed in the PR.
Add codes argument to scale_[fill/colour]_discrete(), closes tidyvers…
Add ability to set default scale_[fill/colour]_discrete() via type=ge…