-
-
Notifications
You must be signed in to change notification settings - Fork 93
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
hjust and vjust ( + line connection + line cross checking) #86
Conversation
…vior. behavior seems reasonable
Thanks again for contributing! I really appreciate your work. 😄 I need a few days to get back to this, but so far your code works very well so I think I'll merge with very minimal modifications. I noticed your figures are pretty big, so I wondered if I could squeeze them down a bit, and it seems that I can! Awesome! 👍 The code I'm running: set.seed(42)
ggplot(mtcars, aes(x = wt, y = 1)) +
geom_point(color = 'red') +
geom_text_repel(
aes(label = rownames(mtcars)),
nudge_y = 0.05,
direction = "x",
angle = 90,
vjust = 0,
segment.size = 0.2
) +
theme_classic(base_size = 16) +
xlim(1, 6) +
ylim(1, 0.8) +
theme(
axis.line.y = element_blank(),
axis.ticks.y = element_blank(),
axis.text.y = element_blank(),
axis.title.y = element_blank()
)
|
Great! Also - happy to follow up on any problems or questions related to this PR, just let me know 😄 |
Hi @AliciaSchep, it seems that the line crossing algorithm is not working in some cases like issue #92. If you have any ideas to fix this without losing the line crossing goodness, please feel free to make another pull. I'll also try to fix this myself if I get a chance, but I might not get around to it for a while. For now I would recommend everyone to use the CRAN version 0.7.0 if they run into this bug. Random thoughts: I fear this might be a challenging one... sometimes I wonder if it would be best to throw away my hacky repulsion code and import some well-tested 2D physics engine like Box2D or similar. I worry ggrepel is reinventing the wheel a bit. I also feel like hacky repulsion code solves 80% of the problems, but 20% of problems still require hand-tuning and it's too much effort to try to solve them with code. |
Update: I have figured out what the cause of the bug is... The problem is that when only some points are labelled the correspondence between points and labels is messed up and labels end up getting associated with wrong point. The not-very-elegant solution (which I had implemented for geom_text_repel but forgot to also implement for geom_label_repel) is to re-order the points so that the labelled ones are first. I will submit a PR later today with a fix for this bug #92. |
This pull request includes adding support for hjust and vjust, as well as two additional changes that were important for having the plots using hjust and vjust actually look reasonable, following up discussion on #69.
The two major additional changes are:
That second change impacts most plots with default args as well. I think it looks decent, but totally understand if you disagree!
Demonstration of hjust: