91
91
geom_violin <- function (mapping = NULL , data = NULL ,
92
92
stat = " ydensity" , position = " dodge" ,
93
93
... ,
94
- draw_quantiles = NULL ,
95
94
trim = TRUE ,
96
95
bounds = c(- Inf , Inf ),
97
96
scale = " area" ,
@@ -110,7 +109,6 @@ geom_violin <- function(mapping = NULL, data = NULL,
110
109
params = list2(
111
110
trim = trim ,
112
111
scale = scale ,
113
- draw_quantiles = draw_quantiles ,
114
112
na.rm = na.rm ,
115
113
orientation = orientation ,
116
114
bounds = bounds ,
@@ -144,7 +142,7 @@ GeomViolin <- ggproto("GeomViolin", Geom,
144
142
flip_data(data , params $ flipped_aes )
145
143
},
146
144
147
- draw_group = function (self , data , ... , draw_quantiles = NULL , flipped_aes = FALSE ) {
145
+ draw_group = function (self , data , ... , flipped_aes = FALSE ) {
148
146
data <- flip_data(data , flipped_aes )
149
147
# Find the points for the line to go all the way around
150
148
data <- transform(data ,
@@ -164,26 +162,15 @@ GeomViolin <- ggproto("GeomViolin", Geom,
164
162
newdata <- flip_data(newdata , flipped_aes )
165
163
166
164
# Draw quantiles if requested, so long as there is non-zero y range
167
- if (length( draw_quantiles ) > 0 & ! scales :: zero_range(range( data $ y ) )) {
168
- if ( ! (all( draw_quantiles > = 0 ) && all( draw_quantiles < = 1 ))) {
169
- cli :: cli_abort( " {.arg draw_quantiles} must be between 0 and 1. " )
170
- }
165
+ if (" quantile " %in% names( newdata )) {
166
+
167
+ quantiles <- newdata [ ! is.na( newdata $ quantile ),]
168
+ quantiles $ group <- match( quantiles $ quantile , unique( quantiles $ quantile ))
171
169
172
- # Compute the quantile segments and combine with existing aesthetics
173
- quantiles <- create_quantile_segment_frame(data , draw_quantiles )
174
- aesthetics <- data [
175
- rep(1 , nrow(quantiles )),
176
- setdiff(names(data ), c(" x" , " y" , " group" )),
177
- drop = FALSE
178
- ]
179
- aesthetics $ alpha <- rep(1 , nrow(quantiles ))
180
- both <- vec_cbind(quantiles , aesthetics )
181
- both <- both [! is.na(both $ group ), , drop = FALSE ]
182
- both <- flip_data(both , flipped_aes )
183
- quantile_grob <- if (nrow(both ) == 0 ) {
170
+ quantile_grob <- if (nrow(quantiles ) == 0 ) {
184
171
zeroGrob()
185
172
} else {
186
- GeomPath $ draw_panel(both , ... )
173
+ GeomPath $ draw_panel(quantiles , ... )
187
174
}
188
175
189
176
ggname(" geom_violin" , grobTree(
0 commit comments