Learn R Programming

ggpmisc (version 0.3.9)

position_nudge_to: Nudge labels to new positions

Description

`position_nudge_to()` is generally useful for adjusting the position of labels or text, both on a discrete or continuous scale. This version from package 'ggpmisc' differs from [ggplot2::position_nudge] in that the coordinates of the new position is given directly, rather than as a displacement from the original location. As other position functions in this package, it preserves the original position to allow the text to be linked back to its original position with a segment or arrow.

Usage

position_nudge_to(x = NULL, y = NULL)

Arguments

x, y

Coordinates of the destination position. A numeric vector of length 1, or of the same length as rows there are in `data`. The default, `NULL`, leaves the original coordinates unchanged.

Details

The new `x` or `y` replace the original ones, while the original coordinates are returned in `x_orig` and `y_orig`.

See Also

[ggplot::position_nudge()], [ggrepel::position_nudge_repel()].

Other position adjustments: position_nudge_center(), position_nudge_line()

Examples

Run this code
# NOT RUN {
df <- data.frame(
  x = c(1,3,2,5,4,2.5),
  y = c(2, 1, 2.5, 1.8, 2.8, 1.5),
  label = c("abc","cd","d","c","bcd","a")
)

ggplot(df, aes(x, y, label = label)) +
  geom_point() +
  geom_text(position = position_nudge_to(y = 3)
  )

ggplot(df, aes(x, y, label = label)) +
  geom_point() +
  geom_linked_text(position = position_nudge_to(y = 3),
                   vjust = -0.2)

# }

Run the code above in your browser using DataLab