Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion R/stat-boxplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion R/utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ has_flipped_aes <- function(data, params = list(), main_is_orthogonal = NA,
}
}

isTRUE(default)
default
}
#' @rdname bidirection
#' @export
Expand Down
30 changes: 24 additions & 6 deletions tests/testthat/_snaps/geom-boxplot.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-geom-boxplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
Loading