Repository navigation
Description
Thank you for maintaining ggplot! I'm really enjoying using it in slides and Rmarkdown files as part of my reporting workflow.
I've been using the ColorBrewer palettes, and recently noticed that I'm not able to reverse their directions as expected. For example, thescale_fill_fermenter() function with a PuOr palette places purple on the low end and orange on the high end. I expected that setting direction = -1 argument would reverse the direction of the palette.
Instead, scale_fill_fermenter() behaves identically for direction = 1 and direction = -1. I can get my desired behavior by setting direction = "horizontal", but this isn't in the docs.
I did a quick search for this behavior in open issues, but the closest thing I could find (#4364) seemed different, so I'm opening the issue. It's not breaking my workflow, but I thought updating the docs or function might save others some time. If the fix is something a new contributor could tackle, I'm happy to give it a shot with a nudge in the right direction!
I've noticed this behavior in ggplot2 version 3.3.3, running in R version 4.0.2., and have a quick trio of examples below.
set.seed(2349)
library(ggplot2)
# Generate some data to plot
n = 100
tb = data.frame(x = runif(n),
y = runif(n))
# Example 1
# Expected: discrete palette, with high values in orange and lows in purple.
# Actual: as expected.
ggplot(tb,
aes(x = x, y = y, fill = y - x)) +
scale_fill_fermenter(palette = 'PuOr') +
geom_point(pch = 21,
color = 'white')# Example 2
# Expected: discrete palette, with high values in *purple* and lows in *orange*
# Actual: same result as example 1. Highs are in *orange*.
ggplot(tb,
aes(x = x, y = y, fill = y - x)) +
scale_fill_fermenter(palette = 'PuOr',
direction = -1) +
geom_point(pch = 21,
color = 'white')# Example 3
# Expected: unknown! Found a stackoverflow answer that suggested this,
# but it's not in the docs.
# Actual: discrete palette with purple on the high end, as desired.
ggplot(tb,
aes(x = x, y = y, fill = y - x)) +
scale_fill_fermenter(palette = 'PuOr',
direction = 'horizontal') +
geom_point(pch = 21,
color = 'white')Created on 2021-04-23 by the reprex package (v0.3.0)



Activity
smouksassi commentedon Apr 23, 2021
the default is direction = - 1 then when you have direction = 1 it is reversed but then if you have anything other than - 1 you get the same results (scales::brewer_pal only tests for direction = -1)
#scales::brewer_pal only tests for direction = -1Created on 2021-04-23 by the reprex package (v2.0.0)
adviksh commentedon Apr 23, 2021
Ah I didn't realize the default direction switches from brewer to distiller/fermenter! This clears up my confusion and solves my problem, so I'm closing the issue — thank you!
Update scale-brewer.R
Update documentation and example in scale-brewer.R to reflect scale_*…