-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Fix bug in discrete position scales with continuous limits (fixes #3918) #3919
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
Conversation
In the example you provided, I don't understand why there's a label "P" underneath the plot panel. Is this really supposed to be there? |
I've modified the reprex a bit to be more realisitic...the drawing of out-of-bounds limits is a separate guides issue for another day. With the new warning: library(ggplot2)
df <- data.frame(x = 1:14, y = -2:-15)
ggplot(df, aes(x, y)) +
scale_y_discrete(limits = -2:-15, labels = LETTERS[1:14])
#> Warning: Continuous limits supplied to discrete scale.
#> Did you mean `limits = factor(...)` or `scale_*_continuous()`? Created on 2020-04-02 by the reprex package (v0.3.0) Also, flagging issue #3918 because it didn't pick up the reference in the title. |
R/scale-expansion.r
Outdated
n_discrete_limits <- length(limits) | ||
} else { | ||
warn( | ||
"Continuous limits supplied to discrete scale.\nDid you mean `limits = factor(...)` or `scale_*_continuous()`?" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder whether this warning is in the wrong place. It's making statements about scale functions and their arguments. Shouldn't it be located inside the appropriate scale functions? (I.e., check the limit
argument to scale_*_discrete()
rather than checking here.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wondering about that too. scale_x|y_discrete()
don't have a limits
arg (they pass it via ...
, so what do you think about putting it in discrete_scale()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, discrete_scale()
seems the right place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, @clauswilke do you have further comments?
No further comments from me. |
This PR fixes the case where only continuous values were provided to a discrete scale, which was also provided continuous limits. I introduced this bug in #3380, which changed the way that discrete scales were expanded into continuous limits (old logic, new logic)
Created on 2020-03-31 by the reprex package (v0.3.0)
Note that
is.discrete()
in this PR is linked tois.discrete()
inScaleDiscretePosition$train()
...I don't think that the discrete scale training logic is likely to change, but the fix in this PR depends on that behaviour. The other approach would be to checkis.null(scale$range$range)
, which is inconvenient the way the expansion code is currently set up (but totally possible if anyone thinks it matters).