Skip to content

More configurable continuous colorscale defaults #3827

Closed

Description

@cpsievert

scale_[fill/colour]_[continuous/binned] have a type argument which provides an entrypoint for customizing the scale's default. Currently, type only supports gradient and viridis. It seems reasonable that it could also support an arbitrary function, which would make the default much more configurable. For example:

library(ggplot2)
scale_colour_custom <- function(...) {
  scale_colour_gradient(..., low = "white", high = "green")
}
options(ggplot2.continuous.colour = scale_colour_custom)
qplot(1:10, 1:10, color = 1:10)

image

Activity

  1. added a commit that references this issue on Feb 20, 2020
    6991106
  2. added a commit that references this issue on Apr 10, 2020
    56e3963
  3. added a commit that references this issue on May 18, 2020
    239ea76
  4. cpsievert commented on May 19, 2020

    @cpsievert
    ContributorAuthor

    Done in #3828

  5. fcecinati commented on Apr 1, 2021

    @fcecinati

    The issue has been closed, but the example above is still not working with the provided syntax in my session (R4.0 ggplot2 3.3.1), returning the followign error:

    > library(ggplot2)
    > scale_colour_custom <- function(...) {
    +   scale_colour_gradient(..., low = "white", high = "green")
    + }
    > options(ggplot2.continuous.colour = scale_colour_custom)
    > qplot(1:10, 1:10, color = 1:10)
    Error in switch(type, gradient = scale_colour_gradient(...), viridis = scale_colour_viridis_c(...),  : 
      EXPR must be a length 1 vector
    

    If a different syntax is needed, could you please provide an example?

    Screenshot of my sessionInfo()
    image

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