I'm trying to use ggrepel to create text labels for charts that I'm working on using R and ggplot2. I'm finding it very useful for repelling away from a single point, but I often run into a problem where it overlaps some other plot objects.
I'm trying to add it to the plot like so:
plot + ggrepel::geom_text_repel(aes(y = Ratio, label = Ratio), direction = "y")
Is there some way that I can tell ggrepel to avoid everything on the ggplot? I've tried searching and coming up with something for this but I'm stuck.
I hope my question is clear enough, thank you.
ggrepel
does not allow avoiding all geoms.
In your case, as a workaround, you can use nudge_y = 0.1
in to shift all labels up.
Often, in such cases, you would want more space for the labels. This can be achieved with e.g. + scale_y_continous(expand = scales::expansion(mult = c(0.05, 0.2)))
ggrepel
will not label, but repel from, points with a empty (""
) label. So in general, as a workaround, you can try to generate data that would cover the other geoms and include that data with empty labels in your geom_text_repel
call.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With