Skip to content

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

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
UweBlock opened this issue Dec 21, 2015 · 2 comments

Comments

@UweBlock
Copy link

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")
@hadley
Copy link
Member

hadley commented Dec 21, 2015

@jiho was this deliberate?

@jiho
Copy link
Contributor

jiho commented Dec 21, 2015

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))

@hadley hadley closed this as completed Jan 26, 2016
@lock lock bot locked as resolved and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants