Skip to content

Commit 3e667f9

Browse files
committed
run-length encode data for violins
1 parent b242644 commit 3e667f9

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

R/position-dodge2.R

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,15 @@ PositionDodge2 <- ggproto("PositionDodge2", PositionDodge,
5858

5959
compute_panel = function(data, params, scales) {
6060
data <- flip_data(data, params$flipped_aes)
61+
key <- NULL
62+
columns <- c("group", "x", "xmin", "xmax")
63+
if (isTRUE(params$group_row == "many")) {
64+
# Run-length encode (RLE) relevant variables
65+
key <- vec_unrep(data[columns])
66+
}
67+
6168
collided <- collide2(
62-
data,
69+
key$key %||% data,
6370
params$width,
6471
name = "position_dodge2",
6572
strategy = pos_dodge2,
@@ -68,7 +75,15 @@ PositionDodge2 <- ggproto("PositionDodge2", PositionDodge,
6875
check.width = FALSE,
6976
reverse = params$reverse
7077
)
71-
flip_data(collided, params$flipped_aes)
78+
79+
if (!is.null(key)) {
80+
# Decode RLE to full data
81+
data[columns] <- vec_rep_each(collided[columns], key$times)
82+
} else {
83+
data <- collided
84+
}
85+
86+
flip_data(data, params$flipped_aes)
7287
}
7388
)
7489

0 commit comments

Comments
 (0)