Skip to content

Allow scale_{colour/fill}_ordinal() to be configured via new ggplot2.ordinal.{colour/fill} global options. #4277

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

Merged
merged 1 commit into from
Apr 8, 2021

Conversation

cpsievert
Copy link
Contributor

Closes #4148.

Could be seen as a follow-up of sorts to #3833, which added the ability to configure qualitative (i.e., non-ordinal) colourscale defaults. This PR adds a similar ability to configure ordinal colourscale defaults via new ggplot2.ordinal.{colour/fill} options:

library(ggplot2)

p <- ggplot(diamonds, aes(price, colour = cut, fill = cut)) + geom_density()
p

image

withr::with_options(
  list(ggplot2.ordinal.fill = viridisLite::cividis(10)), p
)

image

@yutannihilation
Copy link
Member

Thanks, this basically looks good to me.

@thomasp85
Copy link
Member

This seems to deviate a bit from what we do the other places, where we don't fall back through first colour then fill (or vice versa). Any reason for the change?

I'm not against it per se, but I think we need to be consistent

@thomasp85 thomasp85 added this to the ggplot2 3.3.4 milestone Mar 25, 2021
@cpsievert
Copy link
Contributor Author

cpsievert commented Mar 25, 2021

It's consistent with scale_{fill/colour}_discrete (added in #3833).

I don't feel super strongly about it, but it does seem pretty convenient to set both defaults at once, and probably what you want 90% of the time.

@yutannihilation
Copy link
Member

but it does seem pretty convenient to set both defaults at once, and probably what you want 90% of the time.

I agree, but, in the case of specifying a function, it might be undesirable.

#4149 (comment)

We need to improve an error message, at least, but probably it's outside of the scope of this pull request.

@thomasp85
Copy link
Member

@cpsievert i was probably only looking at the continuous implementation. So it seems we have already shipped two different setups😔. Let's keep this in line with discrete as is and think about how we improve on it in the future

@thomasp85 thomasp85 merged commit 0990114 into tidyverse:master Apr 8, 2021
@thomasp85
Copy link
Member

Thanks!

@cpsievert cpsievert deleted the global-ordinal-scale branch April 8, 2021 13:48
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

Successfully merging this pull request may close these issues.

New ggplot2.discrete.fill option doesn't work with ordered factor columns
3 participants