Skip to content

Commit

Permalink
Fix bug in new code
Browse files Browse the repository at this point in the history
Some parameters were not set as needed for dodging.
  • Loading branch information
aphalo committed Feb 21, 2025
1 parent ae3c31e commit e620be0
Show file tree
Hide file tree
Showing 21 changed files with 48 additions and 1,174 deletions.
23 changes: 11 additions & 12 deletions R/position-dodge-nudge-to.R
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,8 @@ position_dodgenudge_to <-
y.distance = "equal",
x.expansion = 0,
y.expansion = 0,
kept.origin = c("original", "none")) {
preserve <- rlang::arg_match(preserve)
kept.origin <- rlang::arg_match(kept.origin)
x.action <- rlang::arg_match(x.action)
y.action <- rlang::arg_match(y.action)
kept.origin = c("dodged", "original", "none")) {

stopifnot("'x' must be NULL or of mode numeric" = length(x) == 0 ||
(!anyNA(x) && mode(x) == "numeric"))
stopifnot("'y' must be NULL or of mode numeric" = length(y) == 0 ||
Expand All @@ -183,13 +180,13 @@ position_dodgenudge_to <-
ggplot2::ggproto(NULL, PositionDodgeNudgeTo,
x = x,
y = y,
x.action = x.action,
y.action = y.action,
x.action = rlang::arg_match(x.action),
y.action = rlang::arg_match(y.action),
x.distance = x.distance,
y.distance = y.distance,
x.expansion = rep_len(x.expansion, 2),
y.expansion = rep_len(y.expansion, 2),
kept.origin = kept.origin,
kept.origin = rlang::arg_match(kept.origin),
width = width,
preserve = rlang::arg_match(preserve)
)
Expand Down Expand Up @@ -217,7 +214,9 @@ PositionDodgeNudgeTo <-
y.expansion = self$y.expansion,
x.reorder = !is.null(self$x) && length(self$x) > 1 && length(self$x) < nrow(data),
y.reorder = !is.null(self$y) && length(self$y) > 1 && length(self$y) < nrow(data),
kept.origin = self$kept.origin
kept.origin = self$kept.origin,
width = self$width,
preserve = self$preserve
)
},

Expand Down Expand Up @@ -355,12 +354,12 @@ position_nudge_to <-
preserve = "total",
x = x,
y = y,
x.action = x.action,
y.action = y.action,
x.action = rlang::arg_match(x.action),
y.action = rlang::arg_match(y.action),
x.distance = x.distance,
y.distance = y.distance,
x.expansion = x.expansion,
y.expansion = y.expansion,
kept.origin = kept.origin
kept.origin = rlang::arg_match(kept.origin)
)
}
2 changes: 1 addition & 1 deletion R/position-dodge-nudge.R
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ position_dodgenudge <-
center = sign),
kept.origin = kept.origin,
width = width,
preserve = rlang::arg_match(preserve)
preserve = preserve
)
}

Expand Down
2 changes: 1 addition & 1 deletion man/position_dodgenudge_to.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions tests-not/test-dodgenudge-to.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# example using future 'ggpp' (>= 0.5.9)
# available at https://aphalo.r-universe.dev/ggpp

library(dplyr)

set.seed(123456)
data <- data.frame(group = rep(c("A", "B", "C"), 3)) %>%
mutate(y = as.numeric(factor(group))*rnorm(n = 9, mean = 0, sd = 0.5),
x = c(1,1,1,2,2,2,3,3,3))

data_labels <-data %>%
filter(x == 1)

library(ggplot2)
library(ggrepel)
library(ggpp)

data %>%
ggplot(aes(x = x, y = y, col = group))+
geom_line(position = position_dodge(width = .3))+
geom_text_repel(data= data_labels,
aes(label = group),
position = position_dodgenudge_to(width = .3, x = .8, kept.origin = "dodged"),
direction = "y",
hjust = "right",
size = 3,
segment.size = .5,
segment.alpha = .5,
segment.linetype = "11",
box.padding = .4,
segment.curvature = 0.4,
segment.ncp = 3,
segment.angle = 20,
) +
theme_minimal()
Binary file modified tests/testthat/Rplots.pdf
Binary file not shown.

This file was deleted.

This file was deleted.

Loading

0 comments on commit e620be0

Please sign in to comment.