-
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
Manual scale limits default to present names of values #4619
Manual scale limits default to present names of values #4619
Conversation
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.
Thanks, while I'm not fully confident yet, this pull request looks the right direction to me. Manual scales are somewhat special, so it's probably a good idea to treat them specially, rather than modifying the whole Scale
.
I have to admit I'm quite confused by this. It's hard to keep track of the many different issues that were filed. I thought we had merged the In any case, @teunbrand, could you add tests and a news item, just like in #4547? It would be good to have a test for every single problem that has shown up. And also, #4471 was exclusive to manual scales, so a fix exclusive to manual scales would be preferred. This argues in favor of this PR over #4547. |
I too feel so...
If I understand correctly, this pull request is based on the same idea. This comment (#4511 (comment)) might help:
|
I hope we can narrow #4547 to only the tests and merge it. Even if we'll choose this pull request, it's good if we can count these prior works on #4547 as a contribution. |
Ah, Ok. I have no concerns about this, except the order of merging. Can we merge the test before merging the fix? |
Yes, let's merge the tests first. |
@clauswilke @yutannihilation |
@teunbrand
|
@banfai Yes of course, I'm sorry for the conflict with your PR and the hassle that came with it! |
@banfai @teunbrand |
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.
Minor comments. Let me for a while to check if this fixes all the problems that are reported so far.
I'd also like to request to add a short comment on the if
branch why limits
needs to be a function.
Co-authored-by: Hiroaki Yutani <[email protected]>
Co-authored-by: Hiroaki Yutani <[email protected]>
Hmm, I have no idea what this error is...
|
Ah, I should have caught that trailing comma, sorry. |
Alright this seems all in its intended state for now :) Thanks for the feedback @yutannihilation!
That seems like a good plan to me, please let me know if you find something. |
@teunbrand This was a better solution, I'm glad we could reconcile the two PRs. |
@banfai |
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 confirmed this solves all the related issues. Now this looks good to me!
c.f. just in case this is useful for someone, this is my quick summary of the issues.
https://gist.github.com/yutannihilation/3d0954fe2a183c08288807215e3c9705
NEWS.md
Outdated
* `scale_*_manual()` no longer displays extra legend keys, or changes their | ||
order, when a named `values` argument has more items than the data. The | ||
previous behaviour can be replicated by using | ||
`scale_*_manual(values = vals, limits = names(vals))`. (@teunbrand, @banfai, | ||
#4511, #4534) |
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.
The word "previous behaviour" might be a bit confusing to those who want further previous behaviour, i.e. behaviour before v3.3.4. How about describing it a bit more explicitly something like "To display all the values
on the legend, use scale_*_manual(values = vals, limits = names(vals))
"? What do you think?
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.
Agreed, "previous behavior" is confusing. Better to describe the specific behavior. I like the proposed sentence.
Perfect, thank you so much! |
I noticed that this fix does not seem to have made its way into the current release on cran (v3.3.6). It is merged into the release candidate branch Update: Just found this comment which suggests that release |
Why this PR?
In ggplot2 v3.3.4, #4471 was introduced to allow fewer items in
values
than auto-detected breaks.This has had some consequences, most notably that an extra legend key was produced if a named
values
was longer than auto-detectedbreaks
(#4511, #4534, #4556, #4545). One workaround is currently to uselimits = force
, which feels unneccessary (#4511 (comment)). Additionally, the ordering of the legend keys was effected by the names in thevalues
argument (#4616).What does this PR do?
This PR aims to revert back to the old behaviour (in most part), while preserving the spirit of #4471. It does so by replacing a vector-based
limits
by a function-basedlimits
that intersects the names of the values by the observed limits.Foreseen problems
Both this PR and #4547 aim to do the same thing and therefore these PRs are in conflict. This PR solely affects manual scales, whereas all scales are affected in #4547.
Examples
Created on 2021-09-15 by the reprex package (v2.0.1)