Learn R Programming

ggpp (version 0.5.1)

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. position_nudge_to() differs from position_nudge in that the coordinates of the new position are 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, kept.origin = "original")

Value

A "Position" object.

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.

kept.origin

One of "original" or "none".

Details

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

See Also

position_nudge, position_nudge_repel.

Other position adjustments: position_dodgenudge(), position_jitternudge(), position_nudge_center(), position_nudge_line(), position_stacknudge()

Examples

Run this code
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_text_s(position = position_nudge_to(y = 3))

Run the code above in your browser using DataLab