0

I have a plot as below

enter image description here

You can reproduce the graph using this code:

set.seed(42)
d <- data.frame(
  x1 = 1,
  y1 = rnorm(10),
  x2 = 2,
  y2 = rnorm(10),
  lab = state.name[1:10]
)

p <- ggplot(d, aes(x1, y1, xend = x2, yend = y2, label = lab, col = lab)) +
  geom_segment(size = 1) +
  guides(color = "none") +
  theme(axis.title.x = element_blank()) +
  geom_text_repel(
    nudge_x = -0.2, direction = "y", hjust = "right"
  ) +
  geom_text_repel(
    aes(x2, y2), nudge_x = 0.1, direction = "y", hjust = "left"
  )

p

The graph is a bit of a muddle, so I want to remove all the labels on the left hand side, leave only the labels on the right hand side. Like this

enter image description here

What should I add into the geom_label_repel() to do that?

Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
NganKD
  • 71
  • 6
  • Remove the first `geom_text_repel`. – stefan Sep 25 '21 at 07:40
  • Ahh, I've tried to use an example that looks similar to my problem but I guess it was a bad example. I've just found out the solution now, we just need to subset the data provided to geom_text to do selective labeling. Thank you anyway!! – NganKD Sep 25 '21 at 08:32

0 Answers0