Skip to content

Inconsistent default directions in scale_fill_brewer() and scale_fill_distiller() #1439

Closed

Description

@UweBlock

The new introduced direction parameter (#1139) has different default values as can be seen in the help file. For brewer the default direction is +1, for distiller the default direction is -1 which is breaking existing codes.
Is there a specific reason for this?
Thanks & brgds,
Uwe

From the Usage section of the help file:

scale_colour_brewer(..., type = "seq", palette = 1, direction = 1)
scale_fill_brewer(..., type = "seq", palette = 1, direction = 1)
scale_colour_distiller(..., type = "seq", palette = 1, direction = -1,
  values = NULL, space = "Lab", na.value = "grey50",
  guide = "colourbar")
scale_fill_distiller(..., type = "seq", palette = 1, direction = -1,
  values = NULL, space = "Lab", na.value = "grey50",
  guide = "colourbar")

Activity

  1. hadley commented on Dec 21, 2015

    @hadley
    Member

    @jiho was this deliberate?

  2. jiho commented on Dec 21, 2015

    @jiho
    Contributor

    It was, the reason for it is:

    1. for sequential scales, darker tones are associated with high values.
    2. for diverging scales, the default direction of the brewer scales associates cold colours with high values and conversely.

    The best choice for 1 is debatable but the default continuous color scale in ggplot2 goes from dark to light, so at least those are consistent. 2 was clearly "wrong".

    Another possibility would be to default to 1 and reverse the colours internally, but I wanted to make it obvious that the setting was different for scale_*_brewer and scale_*_distiller. If it was just me, I would actually reverse the colours for scale_*_brewer too and make this the default.

    Examples

    library("ggplot2")
    library("reshape2")
    library("RColorBrewer")
    d <- melt(volcano, varnames=c("x", "y"), value.name="z")
    
    # default
    ggplot(d, aes(x=x, y=y, fill=z)) + geom_raster()
    # current default
    ggplot(d, aes(x=x, y=y, fill=z)) + geom_raster() + scale_fill_distiller(palette="Blues")
    # "regular" direction (given by RColorBrewer)
    ggplot(d, aes(x=x, y=y, fill=z)) + geom_raster() + scale_fill_distiller(palette="Blues", direction=1)
    ggplot(d, aes(x=x, y=y, fill=z)) + geom_raster() + scale_fill_gradientn(colors=brewer.pal(name="Blues", n=6))
    
    # and with a diverging scale
    ggplot(d, aes(x=x, y=y, fill=z)) + geom_raster() + scale_fill_distiller(palette="Spectral")
    
    ggplot(d, aes(x=x, y=y, fill=z)) + geom_raster() + scale_fill_distiller(palette="Spectral", direction=1)
    ggplot(d, aes(x=x, y=y, fill=z)) + geom_raster() + scale_fill_gradientn(colors=brewer.pal(name="Spectral", n=6))
    
  3. locked as resolved and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions