Skip to content

scale_gradient's palette argument cannot be specified #6365

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
twest820 opened this issue Mar 18, 2025 · 1 comment
Closed

scale_gradient's palette argument cannot be specified #6365

twest820 opened this issue Mar 18, 2025 · 1 comment

Comments

@twest820
Copy link

Needed to set the direction on a gradient, which the docs indicate is can be done by setting palette.

That's broken, though. Looks like lack of checking for an existing palette argument somewhere along the call stack leads to a second palette getting inserted.

ggplot() +
  geom_point(aes(x = seq(0, 10), y = seq(0, 10), color = seq(0, 10))) +
  scale_color_gradient(palette = scales::pal_brewer(direction = -1))
Error in continuous_scale(aesthetics, name = name, palette = pal_seq_gradient(low,  : 
  formal argument "palette" matched by multiple actual arguments

A basic workaround looks to be call the scale directly and give those values to high and low though, depending on the gradient being used, that can compromise perceptual uniformity.

@teunbrand
Copy link
Collaborator

Hi there, thanks for the report! You're right that this doesn't work, but the error here is that palette is a documented parameter while it isn't (not that the argument doesn't work). The documentation side of things has fixed already in #5992 and can be seen in the development docs: https://ggplot2.tidyverse.org/dev/reference/scale_gradient.html.
As for the palettes, these are accessible if you use the continuous_scale() and discrete_scale() constructors. In the future, it'll also be possible to set default palettes via the theme.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants