Skip to content

Commit 8724c8e

Browse files
authored
Fix grid errors when quantiles falls outside of violin (#3254)
1 parent 4e99f95 commit 8724c8e

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ core developer team.
9797

9898
* `geom_rug()` now works with `coord_flip()` (@has2k1, #2987).
9999

100+
* `geom_violin()` no longer throws an error when quantile lines fall outside
101+
the violin polygon (@thomasp85, #3254).
102+
100103
* Default labels are now generated more consistently; e.g., symbols no longer
101104
get backticks, and long expressions are abbreviated with `...`
102105
(@yutannihilation, #2981).

R/geom-violin.r

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,17 @@ GeomViolin <- ggproto("GeomViolin", Geom,
136136
quantiles <- create_quantile_segment_frame(data, draw_quantiles)
137137
aesthetics <- data[
138138
rep(1, nrow(quantiles)),
139-
setdiff(names(data), c("x", "y")),
139+
setdiff(names(data), c("x", "y", "group")),
140140
drop = FALSE
141141
]
142142
aesthetics$alpha <- rep(1, nrow(quantiles))
143143
both <- cbind(quantiles, aesthetics)
144-
quantile_grob <- GeomPath$draw_panel(both, ...)
144+
both <- both[!is.na(both$group), , drop = FALSE]
145+
quantile_grob <- if (nrow(both) == 0) {
146+
zeroGrob()
147+
} else {
148+
GeomPath$draw_panel(both, ...)
149+
}
145150

146151
ggname("geom_violin", grobTree(
147152
GeomPolygon$draw_panel(newdata, ...),

0 commit comments

Comments
 (0)