diff --git a/NEWS.md b/NEWS.md index 9f835349c6..b2b19f4e1e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,8 @@ # ggplot2 3.0.0.9000 +* `geom_boxplot()` now understands the `width` parameter even when used with + a non-standard stat, such as `stat_identity()` (@clauswilke, #2893). + * `scale_*_date()`, `scale_*_time()` and `scale_*_datetime()` can now display a secondary axis that is a __one-to-one__ transformation of the primary axis, implemented using the `sec.axis` argument to the scale constructor diff --git a/R/geom-boxplot.r b/R/geom-boxplot.r index 721c37f775..c32d236739 100644 --- a/R/geom-boxplot.r +++ b/R/geom-boxplot.r @@ -158,6 +158,11 @@ geom_boxplot <- function(mapping = NULL, data = NULL, #' @usage NULL #' @export GeomBoxplot <- ggproto("GeomBoxplot", Geom, + + # need to declare `width`` here in case this geom is used with a stat that + # doesn't have a `width` parameter (e.g., `stat_identity`). + extra_params = c("na.rm", "width"), + setup_data = function(data, params) { data$width <- data$width %||% params$width %||% (resolution(data$x, FALSE) * 0.9)