Examples for 'ggrepel::position_nudge_repel'


Nudge labels a fixed distance from points

Aliases: position_nudge_repel

Keywords:

### ** Examples


df <- data.frame(
  x = c(1,3,2,5),
  y = c("a","c","d","c")
)

ggplot(df, aes(x, y)) +
  geom_point() +
  geom_text_repel(aes(label = y))
plot of chunk example-ggrepel-position_nudge_repel-1
ggplot(df, aes(x, y)) +
  geom_point() +
  geom_text_repel(
    aes(label = y),
    min.segment.length = 0,
    position = position_nudge_repel(x = 0.1, y = 0.15)
  )
plot of chunk example-ggrepel-position_nudge_repel-1
# The values for x and y can be vectors
ggplot(df, aes(x, y)) +
  geom_point() +
  geom_text_repel(
    aes(label = y),
    min.segment.length = 0,
    position = position_nudge_repel(
      x = c(0.1, 0, -0.1, 0),
      y = c(0.1, 0.2, -0.1, -0.2)
    )
  )
plot of chunk example-ggrepel-position_nudge_repel-1
# We can also use geom_text_repel() with arguments nudge_x, nudge_y
ggplot(df, aes(x, y)) +
  geom_point() +
  geom_text_repel(
    aes(label = y),
    min.segment.length = 0,
    nudge_x = 0.1,
    nudge_y = 0.15
  )
plot of chunk example-ggrepel-position_nudge_repel-1
# The arguments nudge_x, nudge_y also accept vectors
ggplot(df, aes(x, y)) +
  geom_point() +
  geom_text_repel(
    aes(label = y),
    min.segment.length = 0,
    nudge_x = c(0.1, 0, -0.1, 0),
    nudge_y = c(0.1, 0.2, -0.1, -0.2)
  )
plot of chunk example-ggrepel-position_nudge_repel-1

[Package ggrepel version 0.9.1 Index]