position_nudge_keep {ggpp} | R Documentation |
Nudge points a fixed distance
Description
The function position_nudge_keep()
has an additional parameters
compared to position_nudge
, obey_grouping
and
by default the same behaviour when the values passed as arguments to x
and y
have length one.
Usage
position_nudge_keep(
x = 0,
y = 0,
obey_grouping = NULL,
kept.origin = c("original", "none")
)
Arguments
x , y |
Amount of vertical and horizontal distance to move. A numeric
vector of length 1, or of the same length as rows there are in |
obey_grouping |
A logical flag indicating whether to obey or not groupings of the observations. By default, grouping is obeyed when both of the variables mapped to x and y are continuous numeric and ignored otherwise. |
kept.origin |
One of |
Details
When x
or y
have length > 1, they are treated
specially. If the lengths is the same as there are rows in data, the nudges
are applied in the order of the rows in data. When they are shorter, they
are recycled and applied to the data values after ordering. This makes it
possible to have alternating mudging right and left or up and down. If
obey_grouping = TRUE
is passed in the call, the alternation will
take place within groups.
As other position functions from package 'ggpp', position_nudge_keep()
by default renames and keeps the original positions of the observations in
data
making it possible to draw connecting segments or conencting
arrows.
Value
A "Position"
object.
Note
Irrespective of the action, the ordering of rows in data
is
preserved.
See Also
Other position adjustments:
position_dodgenudge()
,
position_jitternudge()
,
position_nudge_center()
,
position_nudge_line()
,
position_nudge_to()
,
position_stacknudge()
Examples
df <- data.frame(
x = c(1,3,2,5,4,2.5),
y = c("abc","cd","d","c","bcd","a")
)
# Plain nudging, same as with ggplot2::position_nudge()
ggplot(df, aes(x, y, label = y)) +
geom_point() +
geom_text_s(hjust = "left", vjust = "bottom",
position = position_nudge_keep(x = 0.2, y = 0.2))
# alternating nudging
ggplot(df, aes(x, y, label = y)) +
geom_point() +
geom_text_s(position = position_nudge_keep(x = c(0.2, -0.2)))
# direct nudging
ggplot(df, aes(x, y, label = y)) +
geom_point() +
geom_text_s(position = position_nudge_keep(x = rep_len(c(0.2, -0.2), 6)))