Skip to content

Commit 78660a9

Browse files
authored
Robust position_dodge(preserve = "single") (tidyverse#5928)
* count groups per position instead of position per group * add news bullet
1 parent 79b6e1c commit 78660a9

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# ggplot2 (development version)
22

3+
* `position_dodge(preserve = "single")` now handles multi-row geoms better,
4+
such as `geom_violin()` (@teunbrand based on @clauswilke's work, #2801).
35
* `position_jitterdodge()` now dodges by `group` (@teunbrand, #3656)
46
* The `arrow.fill` parameter is now applied to more line-based functions:
57
`geom_path()`, `geom_line()`, `geom_step()` `geom_function()`, line

R/position-dodge.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ PositionDodge <- ggproto("PositionDodge", Position,
111111
if (identical(self$preserve, "total")) {
112112
n <- NULL
113113
} else {
114-
panels <- unname(split(data, data$PANEL))
115-
ns <- vapply(panels, function(panel) max(table(panel$xmin)), double(1))
116-
n <- max(ns)
114+
n <- vec_unique(data[c("group", "PANEL", "xmin")])
115+
n <- vec_group_id(n[c("PANEL", "xmin")])
116+
n <- max(tabulate(n, attr(n, "n")))
117117
}
118118

119119
list(

0 commit comments

Comments
 (0)