-
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
Improve scales behavior for ordered factors #2179
Conversation
Some of this could be DRY-er, e.g. scale_size_ordinal <- function(...) {
suppressWarnings(scale_size_discrete(...))
} might be better, or change the discrete version to scale_size_discrete <- function(...) {
warning("Using size for a discrete variable is not advised.", call. = FALSE)
scale_size_ordinal(...)
} |
If we're going to go with viridis for ordinal scales then we may not need any additional functions, but if not then perhaps something like this should go in the scales package: seq_ordinal_pal <- function(low, high) {
function(n) {
v <- seq(0, 1, length.out = n)
scales::colour_ramp(c(low, high))(v)
}
} Then scale_colour_ordinal <- function(..., low = "#132B43", high = "#56B1F7",
na.value = "grey50") {
discrete_scale(
"colour",
"sequence",
seq_ordinal_pal(low, high),
na.value = na.value,
...
)
} which produces output like this: d <- diamonds[sample(nrow(diamonds), 1000), ]
ggplot(d, aes(carat, price)) +
geom_point(aes(colour = cut)) |
You need to be careful (or document the aberrations), depending on how you interpolate between the high and low colours of a colourmap, not all generated colours may be part of the continuous version of the colourmap. This will definitely affect colourmaps that aim to perceptually-uniform, like viridis. |
@hadley GitHub isn't letting me request a review but can you tell me what you think of this? I can't remember if we decided on Monday what to do about the ordinal color scales. |
Looks good so far. We should make a decision about ordinal colour scales too. Using viridis seems like a reasonable choice to me. |
Using viridis sounds good to me, so once #2178 gets merged I can add that here. |
I removed Jenny's codecov-related commits and added |
@hadley one quick question before I merge -- since we're making viridis the default for ordered factors, should |
Yes! |
This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/ |
Related to 1526. Ordered factors and regular factors currently behave pretty much the same, but this is not always appropriate. I've added new ordinal scales for
size
,alpha
, andshape
so thatscale_shape_ordinal
throws a warning (butscale_shape_discrete
still does not)scale_size_ordinal
does not throw a warning (butscale_size_discrete
still does)scale_alpha_ordinal
still does not throw a warning (butscale_alpha_discrete
does)Still to do: