diff --git a/NEWS.md b/NEWS.md index 8893fdbd6d..606d2b7c92 100644 --- a/NEWS.md +++ b/NEWS.md @@ -205,6 +205,9 @@ up correct aspect ratio, and draws a graticule. * In all layers that use it, `linemitre` now defaults to 10 (instead of 1) to better match base R. +* `geom_boxplot()` now supplies default value if no `x` aesthetic present + (@foo-bar-baz-qux, #2110). + * `geom_density()` drops groups with fewer than two data points and throws a warning. For groups with two data points, the density values are now calculated with `stats::density` (@karawoo, #2127). diff --git a/R/stat-boxplot.r b/R/stat-boxplot.r index b29eefc34c..d444794afa 100644 --- a/R/stat-boxplot.r +++ b/R/stat-boxplot.r @@ -42,11 +42,15 @@ stat_boxplot <- function(mapping = NULL, data = NULL, #' @usage NULL #' @export StatBoxplot <- ggproto("StatBoxplot", Stat, - required_aes = c("x", "y"), + required_aes = c("y"), non_missing_aes = "weight", + setup_data = function(data, params) { + data$x <- data$x %||% 0 + data + }, setup_params = function(data, params) { - params$width <- params$width %||% (resolution(data$x) * 0.75) + params$width <- params$width %||% (resolution(data$x %||% 0) * 0.75) if (is.double(data$x) && !has_groups(data) && any(data$x != data$x[1L])) { warning(