Skip to content

Commit e620be0

Browse files
committed
Fix bug in new code
Some parameters were not set as needed for dodging.
1 parent ae3c31e commit e620be0

21 files changed

+48
-1174
lines changed

R/position-dodge-nudge-to.R

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,8 @@ position_dodgenudge_to <-
160160
y.distance = "equal",
161161
x.expansion = 0,
162162
y.expansion = 0,
163-
kept.origin = c("original", "none")) {
164-
preserve <- rlang::arg_match(preserve)
165-
kept.origin <- rlang::arg_match(kept.origin)
166-
x.action <- rlang::arg_match(x.action)
167-
y.action <- rlang::arg_match(y.action)
163+
kept.origin = c("dodged", "original", "none")) {
164+
168165
stopifnot("'x' must be NULL or of mode numeric" = length(x) == 0 ||
169166
(!anyNA(x) && mode(x) == "numeric"))
170167
stopifnot("'y' must be NULL or of mode numeric" = length(y) == 0 ||
@@ -183,13 +180,13 @@ position_dodgenudge_to <-
183180
ggplot2::ggproto(NULL, PositionDodgeNudgeTo,
184181
x = x,
185182
y = y,
186-
x.action = x.action,
187-
y.action = y.action,
183+
x.action = rlang::arg_match(x.action),
184+
y.action = rlang::arg_match(y.action),
188185
x.distance = x.distance,
189186
y.distance = y.distance,
190187
x.expansion = rep_len(x.expansion, 2),
191188
y.expansion = rep_len(y.expansion, 2),
192-
kept.origin = kept.origin,
189+
kept.origin = rlang::arg_match(kept.origin),
193190
width = width,
194191
preserve = rlang::arg_match(preserve)
195192
)
@@ -217,7 +214,9 @@ PositionDodgeNudgeTo <-
217214
y.expansion = self$y.expansion,
218215
x.reorder = !is.null(self$x) && length(self$x) > 1 && length(self$x) < nrow(data),
219216
y.reorder = !is.null(self$y) && length(self$y) > 1 && length(self$y) < nrow(data),
220-
kept.origin = self$kept.origin
217+
kept.origin = self$kept.origin,
218+
width = self$width,
219+
preserve = self$preserve
221220
)
222221
},
223222

@@ -355,12 +354,12 @@ position_nudge_to <-
355354
preserve = "total",
356355
x = x,
357356
y = y,
358-
x.action = x.action,
359-
y.action = y.action,
357+
x.action = rlang::arg_match(x.action),
358+
y.action = rlang::arg_match(y.action),
360359
x.distance = x.distance,
361360
y.distance = y.distance,
362361
x.expansion = x.expansion,
363362
y.expansion = y.expansion,
364-
kept.origin = kept.origin
363+
kept.origin = rlang::arg_match(kept.origin)
365364
)
366365
}

R/position-dodge-nudge.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ position_dodgenudge <-
125125
center = sign),
126126
kept.origin = kept.origin,
127127
width = width,
128-
preserve = rlang::arg_match(preserve)
128+
preserve = preserve
129129
)
130130
}
131131

man/position_dodgenudge_to.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests-not/test-dodgenudge-to.R

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# example using future 'ggpp' (>= 0.5.9)
2+
# available at https://aphalo.r-universe.dev/ggpp
3+
4+
library(dplyr)
5+
6+
set.seed(123456)
7+
data <- data.frame(group = rep(c("A", "B", "C"), 3)) %>%
8+
mutate(y = as.numeric(factor(group))*rnorm(n = 9, mean = 0, sd = 0.5),
9+
x = c(1,1,1,2,2,2,3,3,3))
10+
11+
data_labels <-data %>%
12+
filter(x == 1)
13+
14+
library(ggplot2)
15+
library(ggrepel)
16+
library(ggpp)
17+
18+
data %>%
19+
ggplot(aes(x = x, y = y, col = group))+
20+
geom_line(position = position_dodge(width = .3))+
21+
geom_text_repel(data= data_labels,
22+
aes(label = group),
23+
position = position_dodgenudge_to(width = .3, x = .8, kept.origin = "dodged"),
24+
direction = "y",
25+
hjust = "right",
26+
size = 3,
27+
segment.size = .5,
28+
segment.alpha = .5,
29+
segment.linetype = "11",
30+
box.padding = .4,
31+
segment.curvature = 0.4,
32+
segment.ncp = 3,
33+
segment.angle = 20,
34+
) +
35+
theme_minimal()

tests/testthat/Rplots.pdf

0 Bytes
Binary file not shown.

tests/testthat/_snaps/position-nudge/nudge-to-contract-expand-x1.svg

Lines changed: 0 additions & 75 deletions
This file was deleted.

tests/testthat/_snaps/position-nudge/nudge-to-contract-expand-y1.svg

Lines changed: 0 additions & 71 deletions
This file was deleted.

0 commit comments

Comments
 (0)