`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 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.
position_nudge_to(x = NULL, y = NULL, kept.origin = "original")
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.
One of "original" or "none".
A "Position"
object.
The new `x` or `y` replace the original ones, while the original coordinates are returned in `x_orig` and `y_orig`.
[ggplot::position_nudge()], [ggrepel::position_nudge_repel()].
Other position adjustments:
position_dodgenudge()
,
position_jitternudge()
,
position_nudge_center()
,
position_nudge_line()
,
position_stacknudge()
# 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_text_s(position = position_nudge_to(y = 3),
vjust = -0.2)
# }
Run the code above in your browser using DataLab