From 42c86d5d9e0cbdd2363e8f71695afd36e22f847a Mon Sep 17 00:00:00 2001 From: Victor Lei Date: Thu, 12 Oct 2017 23:19:13 -0400 Subject: [PATCH] Added support for univariate box plots with no `x` aesthetic (#2110). --- NEWS.md | 2 ++ R/stat-boxplot.r | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index 885897ebc6..709eba2fba 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # ggplot2 2.2.1.9000 +* Added support for univariate box plots with no `x` aesthetic (@foo-bar-baz-qux, #2110). + * Fixed bug when setting strips to `element_blank()` (@thomasp85). * Strips gain margins on all sides by default. This means that to fully justify diff --git a/R/stat-boxplot.r b/R/stat-boxplot.r index 02c2249918..4dbb843d25 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(