Skip to content

Commit c44ad91

Browse files
committed
position_nudge() accepts nudge aesthetics
1 parent e7de35e commit c44ad91

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

R/position-nudge.R

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#' ggplot(df, aes(x, y)) +
2727
#' geom_point() +
2828
#' geom_text(aes(label = y), nudge_y = -0.1)
29-
position_nudge <- function(x = 0, y = 0) {
29+
position_nudge <- function(x = NULL, y = NULL) {
3030
ggproto(NULL, PositionNudge,
3131
x = x,
3232
y = y
@@ -38,11 +38,16 @@ position_nudge <- function(x = 0, y = 0) {
3838
#' @usage NULL
3939
#' @export
4040
PositionNudge <- ggproto("PositionNudge", Position,
41-
x = 0,
42-
y = 0,
41+
x = NULL,
42+
y = NULL,
43+
44+
default_aes = aes(nudge_x = 0, nudge_y = 0),
4345

4446
setup_params = function(self, data) {
45-
list(x = self$x, y = self$y)
47+
list(
48+
x = self$x %||% data$nudge_x,
49+
y = self$y %||% data$nudge_y
50+
)
4651
},
4752

4853
compute_layer = function(self, data, params, layout) {

0 commit comments

Comments
 (0)