-
Notifications
You must be signed in to change notification settings - Fork 2.1k
resolution(<mapped_discrete>) should not always return 1 (ggplot2 3.5.0) #5709
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
Comments
The change was intentional and was designed to solve #5211. The idea was that when some variable is a |
Hmm, I would argue this mixes concerns: resolution used to be a very straightforward function with a simple contract: you give it a vector and it returns "the smallest non-zero distance between adjacent values" (per the docs --- which are no longer correct). The exception for Now its contract is: you give it a vector and it returns the smallest non-zero distance between adjacent values, unless you give it a mapped_discrete, in which case it might give you the smallest non-zero distance between adjacent values depending on if that value happens to be 1. I think a cleaner solution would be for Another solution might be to change the heuristic in |
You raise some useful points and maybe it is better to make an exception for #5211 rather than adjusting |
Cool makes sense! Congrats on the great release btw. FWIW, thinking about this more, a relatively simple contract could be: given |
Simply reverting the solution and making an exception for |
Makes sense. Though, does returning min(d, 1) for mapped_discrete not solve the problem for those other use cases? Might save you an extra argument and a more complicated set of post conditions on the function. |
I noticed a minor bug in ggdist under ggplot2 3.5.0, which is caused by a change in behavior that I believe is a regression:
resolution(<mapped_discrete>)
now always returns 1.E.g. in 3.4:
And in 3.5:
I believe the old behavior is correct.
mapped_discrete
is applied after discrete values are scaled into (0,1), and when asking the resolution one wants to know the resolution in plot units, not in original data units. This would also be consistent with whatresolution()
does on continuous variables, as it would be impossible to return the resolution in original data units when passed anumeric
, as that information is not retained.From my side it's an easy fix to just cast to
numeric()
before usingresolution()
, but I am fairly sure I should not have to do that.The text was updated successfully, but these errors were encountered: