Skip to content

Improvements to qualitative color scaling #3826

Closed

Description

@cpsievert

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.

Activity

  1. added 2 commits that reference this issue on Feb 19, 2020
    d309b0a
    bafa536
  2. hadley commented on Feb 21, 2020

    @hadley
    Member

    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.

  3. cpsievert commented on Feb 22, 2020

    @cpsievert
    ContributorAuthor

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

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

  4. hadley commented on Feb 22, 2020

    @hadley
    Member

    I was thinking of a scale function

  5. added a commit that references this issue on Feb 24, 2020
    b3bc1a7
  6. added a commit that references this issue on Apr 10, 2020
    312009a
  7. modified the milestones: ggplot2 3.4.0, on Apr 29, 2020
  8. clauswilke commented on Apr 29, 2020

    @clauswilke
    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.

  9. added 2 commits that reference this issue on May 18, 2020
    5b4f19d
    b71d67d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions