Skip to content

Commit 2fec60e

Browse files
committed
stat param is named quantiles
1 parent d888f69 commit 2fec60e

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

R/stat-ydensity.R

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#' @param drop Whether to discard groups with less than 2 observations
88
#' (`TRUE`, default) or keep such groups for position adjustment purposes
99
#' (`FALSE`).
10-
#' @param draw_quantiles If not `NULL` (default), compute the `quantile` variable
10+
#' @param quantiles If not `NULL` (default), compute the `quantile` variable
1111
#' and draw horizontal lines at the given quantiles in `geom_violin()`.
1212
#'
1313
#' @eval rd_computed_vars(
@@ -19,7 +19,7 @@
1919
#' counts or to a constant maximum width.",
2020
#' n = "Number of points.",
2121
#' 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."
2323
#' )
2424
#'
2525
#' @seealso [geom_violin()] for examples, and [stat_density()]
@@ -29,7 +29,7 @@
2929
stat_ydensity <- function(mapping = NULL, data = NULL,
3030
geom = "violin", position = "dodge",
3131
...,
32-
draw_quantiles = NULL,
32+
quantiles = c(0.25, 0.50, 0.75),
3333
bw = "nrd0",
3434
adjust = 1,
3535
kernel = "gaussian",
@@ -60,7 +60,7 @@ stat_ydensity <- function(mapping = NULL, data = NULL,
6060
drop = drop,
6161
na.rm = na.rm,
6262
bounds = bounds,
63-
draw_quantiles = draw_quantiles,
63+
quantiles = quantiles,
6464
...
6565
)
6666
)
@@ -86,7 +86,7 @@ StatYdensity <- ggproto("StatYdensity", Stat,
8686
compute_group = function(self, data, scales, width = NULL, bw = "nrd0", adjust = 1,
8787
kernel = "gaussian", trim = TRUE, na.rm = FALSE,
8888
drop = TRUE, flipped_aes = FALSE, bounds = c(-Inf, Inf),
89-
draw_quantiles = NULL) {
89+
quantiles = c(0.25, 0.50, 0.75)) {
9090
if (nrow(data) < 2) {
9191
if (isTRUE(drop)) {
9292
cli::cli_warn(c(
@@ -121,19 +121,19 @@ StatYdensity <- ggproto("StatYdensity", Stat,
121121
}
122122
dens$width <- width
123123

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.")
127127
}
128128
if (!is.null(data[["weight"]]) || !all(data[["weight"]] == 1)) {
129129
cli::cli_warn(
130-
"{.arg draw_quantiles} for weighted data is not implemented."
130+
"{.arg quantiles} for weighted data is not implemented."
131131
)
132132
}
133-
quants <- quantile(data$y, probs = draw_quantiles)
133+
quants <- quantile(data$y, probs = quantiles)
134134
quants <- data_frame0(
135135
y = unname(quants),
136-
quantile = draw_quantiles
136+
quantile = quantiles
137137
)
138138

139139
# Interpolate other metrics
@@ -152,12 +152,12 @@ StatYdensity <- ggproto("StatYdensity", Stat,
152152
compute_panel = function(self, data, scales, width = NULL, bw = "nrd0", adjust = 1,
153153
kernel = "gaussian", trim = TRUE, na.rm = FALSE,
154154
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)) {
156156
data <- flip_data(data, flipped_aes)
157157
data <- ggproto_parent(Stat, self)$compute_panel(
158158
data, scales, width = width, bw = bw, adjust = adjust, kernel = kernel,
159159
trim = trim, na.rm = na.rm, drop = drop, bounds = bounds,
160-
draw_quantiles = draw_quantiles
160+
quantiles = quantiles
161161
)
162162
if (!drop && any(data$n < 2)) {
163163
cli::cli_warn(

0 commit comments

Comments
 (0)