7
7
# ' @param drop Whether to discard groups with less than 2 observations
8
8
# ' (`TRUE`, default) or keep such groups for position adjustment purposes
9
9
# ' (`FALSE`).
10
- # ' @param draw_quantiles If not `NULL` (default), compute the `quantile` variable
10
+ # ' @param quantiles If not `NULL` (default), compute the `quantile` variable
11
11
# ' and draw horizontal lines at the given quantiles in `geom_violin()`.
12
12
# '
13
13
# ' @eval rd_computed_vars(
19
19
# ' counts or to a constant maximum width.",
20
20
# ' n = "Number of points.",
21
21
# ' width = "Width of violin bounding box.",
22
- # ' quantile = "Whether the row is part of the `draw_quantiles ` computation."
22
+ # ' quantile = "Whether the row is part of the `quantiles ` computation."
23
23
# ' )
24
24
# '
25
25
# ' @seealso [geom_violin()] for examples, and [stat_density()]
29
29
stat_ydensity <- function (mapping = NULL , data = NULL ,
30
30
geom = " violin" , position = " dodge" ,
31
31
... ,
32
- draw_quantiles = NULL ,
32
+ quantiles = c( 0.25 , 0.50 , 0.75 ) ,
33
33
bw = " nrd0" ,
34
34
adjust = 1 ,
35
35
kernel = " gaussian" ,
@@ -60,7 +60,7 @@ stat_ydensity <- function(mapping = NULL, data = NULL,
60
60
drop = drop ,
61
61
na.rm = na.rm ,
62
62
bounds = bounds ,
63
- draw_quantiles = draw_quantiles ,
63
+ quantiles = quantiles ,
64
64
...
65
65
)
66
66
)
@@ -86,7 +86,7 @@ StatYdensity <- ggproto("StatYdensity", Stat,
86
86
compute_group = function (self , data , scales , width = NULL , bw = " nrd0" , adjust = 1 ,
87
87
kernel = " gaussian" , trim = TRUE , na.rm = FALSE ,
88
88
drop = TRUE , flipped_aes = FALSE , bounds = c(- Inf , Inf ),
89
- draw_quantiles = NULL ) {
89
+ quantiles = c( 0.25 , 0.50 , 0.75 ) ) {
90
90
if (nrow(data ) < 2 ) {
91
91
if (isTRUE(drop )) {
92
92
cli :: cli_warn(c(
@@ -121,19 +121,19 @@ StatYdensity <- ggproto("StatYdensity", Stat,
121
121
}
122
122
dens $ width <- width
123
123
124
- if (! is.null(draw_quantiles )) {
125
- if (! (all(draw_quantiles > = 0 ) && all(draw_quantiles < = 1 ))) {
126
- cli :: cli_abort(" {.arg draw_quantiles } must be between 0 and 1." )
124
+ if (! is.null(quantiles )) {
125
+ if (! (all(quantiles > = 0 ) && all(quantiles < = 1 ))) {
126
+ cli :: cli_abort(" {.arg quantiles } must be between 0 and 1." )
127
127
}
128
128
if (! is.null(data [[" weight" ]]) || ! all(data [[" weight" ]] == 1 )) {
129
129
cli :: cli_warn(
130
- " {.arg draw_quantiles } for weighted data is not implemented."
130
+ " {.arg quantiles } for weighted data is not implemented."
131
131
)
132
132
}
133
- quants <- quantile(data $ y , probs = draw_quantiles )
133
+ quants <- quantile(data $ y , probs = quantiles )
134
134
quants <- data_frame0(
135
135
y = unname(quants ),
136
- quantile = draw_quantiles
136
+ quantile = quantiles
137
137
)
138
138
139
139
# Interpolate other metrics
@@ -152,12 +152,12 @@ StatYdensity <- ggproto("StatYdensity", Stat,
152
152
compute_panel = function (self , data , scales , width = NULL , bw = " nrd0" , adjust = 1 ,
153
153
kernel = " gaussian" , trim = TRUE , na.rm = FALSE ,
154
154
scale = " area" , flipped_aes = FALSE , drop = TRUE ,
155
- bounds = c(- Inf , Inf ), draw_quantiles = NULL ) {
155
+ bounds = c(- Inf , Inf ), quantiles = c( 0.25 , 0.50 , 0.75 ) ) {
156
156
data <- flip_data(data , flipped_aes )
157
157
data <- ggproto_parent(Stat , self )$ compute_panel(
158
158
data , scales , width = width , bw = bw , adjust = adjust , kernel = kernel ,
159
159
trim = trim , na.rm = na.rm , drop = drop , bounds = bounds ,
160
- draw_quantiles = draw_quantiles
160
+ quantiles = quantiles
161
161
)
162
162
if (! drop && any(data $ n < 2 )) {
163
163
cli :: cli_warn(
0 commit comments