-
-
Notifications
You must be signed in to change notification settings - Fork 96
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
geom_text_repel with hjust and vjust #188
Comments
@glorious1 Sorry, but I don't understand your question. You might consider sharing code or an image. |
For example, if you run this code on your machine, you should (hopefully) get exactly the same layout that I got in this post. Since the size of the figure and font size also affects the layout, your plot might look a bit different. library(ggrepel)
#> Loading required package: ggplot2
set.seed(1)
d <- data.frame(
x = runif(10),
y = runif(10),
label = letters[1:10]
)
ggplot(d) +
aes(x, y, label = label) +
geom_point() +
geom_text_repel() Created on 2021-03-15 by the reprex package (v0.3.0) |
Luckily, I left a useful comment in the docs that might answer your question about text justification: Lines 23 to 27 in f5513ae
In other words, we can't have our cake and eat it, too. Either the labels are going to move or not. Suppose we restrict movement with I hope that gives you some clarity! |
I think you might want to try The nudging parameters give you some control to change the initial starting position of each text label before the physical repulsion simulation runs. |
@glorious1 Using values outside the range 0..1 for justification is problematic. You may want to use nudging and justification together. You could disable repulsion if you have manually set the location of the text. |
Summary
This is just a question. I'm labeling points plotted on a map. To optimize position and avoid features in other layers of the map, the data has hJust and vJust columns with values customized for each point. All I want to do is put the labels in those positions, but moved away from the point so the point and text don't overlap. There is no problem with overlap between labels or edge of the map.
When I use the hjust and vjust aesthetics with geom_text_repel, all sorts of weird things happen. Is there any way to respect that, but just push them off the point? Of course the direction they need to move depends on the justification.
Minimal code example
Here is the minimum amount of code needed to demonstrate the issue:
Here is an image of the output produced by the code:
IMAGE
Suggestions
This is my proposal for how to solve the issue.
Version information
Here is the output from
sessionInfo()
in my R session:The text was updated successfully, but these errors were encountered: