-
-
Notifications
You must be signed in to change notification settings - Fork 95
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
Update compute_just() to match 'ggplot2' and fix bad justification with rotation #196
Conversation
I made a mistake and also had left behind some commented out code. Now fixed, I hope.
Merge edited master before creating new pull-request.
As compute_just() was updated in ggplot2 to fix a bug, we replace the old version also copied from ggplot2 with the version in a current pull-request.
@slowkow I need to refresh my memory, please give me a couple of days. I will check this pull request (#196) against the code in ggplot2 and let you know if they still are consistent. Anyway, there were two different questions: 1) the bug in ggplot2 related to justification (#196) and 2) the renaming of the values returned by the position functions so that |
@slowkow Hi Kamil. I have been checking justification in ggrepel. There is a bug in |
@slowkow Hi. I do not see any difference in behaviour between this pull request and ggrepel installed from CRAN, except for angle > 45 and angle < -45, which is expected. The problem with the bug in |
This commit uses special text justification positioning code when values of hjust or vjust are not equal to 0.5, or else skips that code.
For angles multiple of 180 degrees the code is now working, for other angles justification is too much. There also seems to be some oddity with the box.height and box.width.
There is still some error in the sizes but small and all angles working.
@slowkow Hi. I have made quite some progress with the justification combined with rotation. I do not think the code is yet ready for release or merging as there are some borderline cases like multi-line rotated labels that are not put into the best place. Insights until now: 1) However, although the code works qualitatively well with different The problem in #171 could be related to this, but I am not yet sure. Using I pushed these code edits, but as I need to stop for today, I will added some reprex examples later in the week. |
This was a bad guess on my part, what was happening is that with rotation the height and width of the bounding box were swapped with respect to the height and width of the label string! Important |
Thank you so much for the update! When you let me know it is ready for merge, and I will try to run it on my system. Do you think it might be a good idea to create a new vignette with all of your test cases (rotations, justifications) on a single page? Maybe this could facilitate catching issues? I like your examples. |
Initial position is now correct. Bug remaining: Segment attached to text box on wrong side for some rotation values.
box.height and box.width are no longer used.
I think unit tests would be better (I can add some of the examples as tests using testthat). I think this code is now good to go. However, repulsion and segments are failing for some rotation angles. I will open a separate issue for these. Given these additional problems it could be safer for you to keep this code in a branch different from master/main until the other problems related to roation are fixed. |
Add unit tests using 'vdiffr' to detect changes in plots. Cases that are currently producing "bad" plots are commented out.
Suggests are needed for unit tests
I added a call to "warn" for angles that deviate from a value multiple of 90 degrees by more than 5 degrees.
@slowkow I have now added unit tests for justification with rotation and a warning about repulsion when rotation angles are not a multiple of 90 degrees. I think this pull request is ready to be merged. The plots in the ggrepel vignette Examples look o.k. to me when built using pull request #196. I am testing locally under Windows 10 and R 4.1.1. I have also built the vignette of package 'ggpp' using this pull request and it also looks fine to me. I think the new "nudge functions" work very nicely together with the repulsive geoms. It is as if the nudging "encourages" the repulsion to be applied more consistently in a "good" direction. The section on nudging of the 'ggpp' vignette has several examples. |
This is a follow-up to #194. I made a pull request to 'ggplot2' fixing a bug in the handling of text justification for angles > 45 and < -45. The cause behind the bug was that the code now replaced ignored that the obvious interpretation of "inward" and "outward" refers to the plot while justification of the text is relative to the orientation of the text. The pull request has been now accepted and merged into the master branch of 'ggplot2'.