-
Notifications
You must be signed in to change notification settings - Fork 2k
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
unexpected behavior when setting named vector for default colour/fill #5013
Comments
did you want to use scale fill manual ? this is not how scale discrete is to be used |
By "is to be used," do you mean default discrete scales should not be named? I guess I might come to understand a principled stand on this, however it would avoid confusion if these scales were then |
Thanks for catching. I too feel it's a bit confusing at least that the behavior is different from library(ggplot2)
ggplot(mpg[mpg$cyl != 5 & mpg$cyl != 8,]) +
aes(x=hwy, fill=factor(cyl)) +
geom_density() +
scale_fill_manual(values = c("4"="red", "8"="blue", "6"="green")) Created on 2022-11-05 with reprex v2.0.2 |
The issue would be resolved if we remove the Line 224 in ed6afe5
But perhaps the broader question is whether we want to support named palettes in the options? |
First, thanks for adding this functionality to ggplot2 - it has been enormously useful in my day-to-day coding. Now on to the issue:
When setting a default color palette using
ggplot2.options.discrete.colour
orggplot2.options.discrete.fill
, the plotting function will only pull a subset of the submitted vector of length equal to the number of unique colours needed. This works fine for unnamed color vectors, however it has undesirable behavior when the relevant named elements occur outside of this subset.Created on 2022-10-14 by the reprex package (v2.0.1)
The text was updated successfully, but these errors were encountered: