From 198bf7a8cbec0bef92a858b5398f808093153cc4 Mon Sep 17 00:00:00 2001 From: Dewey Dunnington Date: Thu, 9 May 2019 13:28:00 -0300 Subject: [PATCH 1/3] fix typo in geom_boxplot comment --- R/geom-boxplot.r | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/geom-boxplot.r b/R/geom-boxplot.r index 93e85a5710..a2c47fb420 100644 --- a/R/geom-boxplot.r +++ b/R/geom-boxplot.r @@ -159,7 +159,7 @@ geom_boxplot <- function(mapping = NULL, data = NULL, #' @export GeomBoxplot <- ggproto("GeomBoxplot", Geom, - # need to declare `width`` here in case this geom is used with a stat that + # 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"), From 8ee5f88f79ba1c2c25ed5189c5a745be3934176a Mon Sep 17 00:00:00 2001 From: Dewey Dunnington Date: Thu, 9 May 2019 13:37:00 -0300 Subject: [PATCH 2/3] better error message when geom_boxplot() gets data with more than 1 row (Fixes #3316) --- R/geom-boxplot.r | 8 ++++++++ tests/testthat/test-geom-boxplot.R | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/R/geom-boxplot.r b/R/geom-boxplot.r index a2c47fb420..39e12b2310 100644 --- a/R/geom-boxplot.r +++ b/R/geom-boxplot.r @@ -200,6 +200,14 @@ GeomBoxplot <- ggproto("GeomBoxplot", Geom, outlier.alpha = NULL, notch = FALSE, notchwidth = 0.5, varwidth = FALSE) { + # this may occur when using geom_boxplot(stat = "identity") + if (nrow(data) != 1) { + stop( + "Can't draw more than one boxplot per group. Did you forget aes(group=...)?", + call. = FALSE + ) + } + common <- list( colour = data$colour, size = data$size, diff --git a/tests/testthat/test-geom-boxplot.R b/tests/testthat/test-geom-boxplot.R index 32367558dd..99ae3ab511 100644 --- a/tests/testthat/test-geom-boxplot.R +++ b/tests/testthat/test-geom-boxplot.R @@ -47,6 +47,16 @@ test_that("boxes with variable widths do not overlap", { expect_false(any(duplicated(xid))) }) +test_that("boxplots with a group size >1 error", { + p <- ggplot( + data_frame(x = "one value", y = 3, value = 4:6), + aes(x, ymin = 0, lower = 1, middle = y, upper = value, ymax = 10) + ) + + geom_boxplot(stat = "identity") + + expect_equal(nrow(layer_data(p, 1)), 3) + expect_error(layer_grob(p, 1), "Can't draw more than one boxplot") +}) # Visual tests ------------------------------------------------------------ From a038a3b676854c6426cd8f46cbcf3179d45f8309 Mon Sep 17 00:00:00 2001 From: Dewey Dunnington Date: Thu, 9 May 2019 17:19:10 -0300 Subject: [PATCH 3/3] Fix typo, Fixes #3316 --- R/geom-boxplot.r | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/geom-boxplot.r b/R/geom-boxplot.r index 39e12b2310..246a0a13f9 100644 --- a/R/geom-boxplot.r +++ b/R/geom-boxplot.r @@ -203,7 +203,7 @@ GeomBoxplot <- ggproto("GeomBoxplot", Geom, # this may occur when using geom_boxplot(stat = "identity") if (nrow(data) != 1) { stop( - "Can't draw more than one boxplot per group. Did you forget aes(group=...)?", + "Can't draw more than one boxplot per group. Did you forget aes(group = ...)?", call. = FALSE ) }