diff --git a/R/stat-boxplot.R b/R/stat-boxplot.R index 41819e5e1e..ff51b8354d 100644 --- a/R/stat-boxplot.R +++ b/R/stat-boxplot.R @@ -23,7 +23,13 @@ StatBoxplot <- ggproto("StatBoxplot", Stat, setup_params = function(self, data, params) { params$flipped_aes <- has_flipped_aes(data, params, main_is_orthogonal = TRUE, group_has_equal = TRUE, - main_is_optional = TRUE) + main_is_optional = TRUE, + default = NA) + + if (is.na(params$flipped_aes)) { + cli::cli_warn("Orientation is not uniquely specified when both the x and y aesthetics are continuous. Picking default orientation 'x'.") + params$flipped_aes <- FALSE + } data <- flip_data(data, params$flipped_aes) has_x <- !(is.null(data$x) && is.null(params$x)) diff --git a/R/utilities.R b/R/utilities.R index 348430fd12..ca06985f26 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -562,7 +562,7 @@ has_flipped_aes <- function(data, params = list(), main_is_orthogonal = NA, } } - isTRUE(default) + as.logical(default)[1] } #' @rdname bidirection #' @export diff --git a/tests/testthat/_snaps/geom-boxplot.md b/tests/testthat/_snaps/geom-boxplot.md index 10e75bb438..8af5e6140b 100644 --- a/tests/testthat/_snaps/geom-boxplot.md +++ b/tests/testthat/_snaps/geom-boxplot.md @@ -1,17 +1,35 @@ # geom_boxplot for continuous x gives warning if more than one x (#992) - Continuous x aesthetic - i did you forget `aes(group = ...)`? + Code + p <- bplot(aes(x, y)) + Condition + Warning: + Orientation is not uniquely specified when both the x and y aesthetics are continuous. Picking default orientation 'x'. + Warning: + Continuous x aesthetic + i did you forget `aes(group = ...)`? --- - Continuous x aesthetic - i did you forget `aes(group = ...)`? + Code + p <- bplot(aes(x, y), facet_wrap(~x)) + Condition + Warning: + Orientation is not uniquely specified when both the x and y aesthetics are continuous. Picking default orientation 'x'. + Warning: + Continuous x aesthetic + i did you forget `aes(group = ...)`? --- - Continuous x aesthetic - i did you forget `aes(group = ...)`? + Code + p <- bplot(aes(Sys.Date() + x, y)) + Condition + Warning: + Orientation is not uniquely specified when both the x and y aesthetics are continuous. Picking default orientation 'x'. + Warning: + Continuous x aesthetic + i did you forget `aes(group = ...)`? # boxplots with a group size >1 error diff --git a/tests/testthat/test-geom-boxplot.R b/tests/testthat/test-geom-boxplot.R index 9d977501ff..82c45c3fb7 100644 --- a/tests/testthat/test-geom-boxplot.R +++ b/tests/testthat/test-geom-boxplot.R @@ -42,9 +42,9 @@ test_that("geom_boxplot for continuous x gives warning if more than one x (#992) ggplot_build(ggplot(dat, aes) + geom_boxplot(aes) + extra) } - expect_snapshot_warning(bplot(aes(x, y))) - expect_snapshot_warning(bplot(aes(x, y), facet_wrap(~x))) - expect_snapshot_warning(bplot(aes(Sys.Date() + x, y))) + expect_snapshot(p <- bplot(aes(x, y))) + expect_snapshot(p <- bplot(aes(x, y), facet_wrap(~x))) + expect_snapshot(p <- bplot(aes(Sys.Date() + x, y))) expect_silent(bplot(aes(x, group = x, y))) expect_silent(bplot(aes(1, y)))