Skip to content

Improvements to qualitative color scaling #3826

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

Closed
cpsievert opened this issue Feb 19, 2020 · 4 comments · Fixed by #3833
Closed

Improvements to qualitative color scaling #3826

cpsievert opened this issue Feb 19, 2020 · 4 comments · Fixed by #3833

Comments

@cpsievert
Copy link
Contributor

cpsievert commented Feb 19, 2020

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.

@hadley
Copy link
Member

hadley commented 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
Copy link
Contributor Author

i.e. making the default type a parameter that you could set.

Yea, so something like codes = getOption("ggplot2.discrete.colour", default = "Okabe-Ito")?

@hadley
Copy link
Member

hadley commented Feb 22, 2020

I was thinking of a scale function

@clauswilke
Copy link
Member

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.

cpsievert added a commit to cpsievert/ggplot2 that referenced this issue May 18, 2020
…tOption('ggplot2.discrete.[fill/colour]') argument, closes tidyverse#3826
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants