Skip to content

Commit 0867837

Browse files
committed
dodge by max number of groups per panel/position
1 parent 28aec3a commit 0867837

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

R/position-jitterdodge.R

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,9 @@ PositionJitterdodge <- ggproto("PositionJitterdodge", Position,
4747
flipped_aes <- has_flipped_aes(data)
4848
data <- flip_data(data, flipped_aes)
4949
width <- self$jitter.width %||% (resolution(data$x, zero = FALSE, TRUE) * 0.4)
50-
# Adjust the x transformation based on the number of 'dodge' variables
51-
possible_dodge <- c("fill", "colour", "linetype", "shape", "size", "alpha")
52-
dodgecols <- intersect(possible_dodge, colnames(data))
53-
if (length(dodgecols) == 0) {
54-
cli::cli_abort(c(
55-
"{.fn position_jitterdodge} requires at least one aesthetic to dodge by.",
56-
i = "Use one of {.or {.val {possible_dodge}}} aesthetics."
57-
))
58-
}
59-
ndodge <- lapply(data[dodgecols], levels) # returns NULL for numeric, i.e. non-dodge layers
60-
ndodge <- vec_unique_count(unlist(ndodge))
50+
51+
ndodge <- split(data$group, list(data$PANEL, data$x))
52+
ndodge <- max(vapply(ndodge, vec_unique_count, integer(1)))
6153

6254
list(
6355
dodge.width = self$dodge.width,

0 commit comments

Comments
 (0)