I'm trying to have text labels not overlap with the data points in a scatterplot made in ggplot2.
I've tried using the nudge_ arguments in geom_text():
library(ggplot2)
df <- data.frame(trt = c("a", "b", "c"),
resp = c(2, 3, 4))
ggplot(df, aes(resp, trt)) +
geom_point() +
geom_text(aes(label = resp , nudge_y = 2, nudge_x = 2))
However, as we can see, the text overlaps with the point:

Is there any way we can fix this? Also, what's the use of nudge_x and nudge_y? I don't quite get it from the manual.
The issue was that nudge_x & nudge_y should be outside of aesthetics.
df <- data.frame(trt = c("a", "b", "c"), resp = c(2, 3, 4))
ggplot(df, aes(resp, trt)) +
geom_point() +
geom_text(aes(label = resp), nudge_y = -0.1)
This fixes the issue. I have reduced nudge_y values.
Here's the graph:

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