Skip to content

Commit f408588

Browse files
committed
add warning when orientation is ambiguous fixes #4250
1 parent 961b194 commit f408588

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

R/stat-boxplot.R

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,13 @@ StatBoxplot <- ggproto("StatBoxplot", Stat,
2323
setup_params = function(self, data, params) {
2424
params$flipped_aes <- has_flipped_aes(data, params, main_is_orthogonal = TRUE,
2525
group_has_equal = TRUE,
26-
main_is_optional = TRUE)
26+
main_is_optional = TRUE,
27+
default = NA)
28+
29+
if (is.na(params$flipped_aes)) {
30+
cli::cli_warn("Warning: Orientation is not uniquely specified when both the x and y aesthetics are continuous. Picking default orientation 'x'.")
31+
params$flipped_aes <- FALSE
32+
}
2733
data <- flip_data(data, params$flipped_aes)
2834

2935
has_x <- !(is.null(data$x) && is.null(params$x))

R/utilities.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ has_flipped_aes <- function(data, params = list(), main_is_orthogonal = NA,
562562
}
563563
}
564564

565-
isTRUE(default)
565+
default
566566
}
567567
#' @rdname bidirection
568568
#' @export

tests/testthat/_snaps/geom-boxplot.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
# geom_boxplot for continuous x gives warning if more than one x (#992)
22

3-
Continuous x aesthetic
4-
i did you forget `aes(group = ...)`?
3+
Warning: Orientation is not uniquely specified when both the x and y aesthetics are continuous. Picking default orientation 'x'.
54

65
---
76

8-
Continuous x aesthetic
9-
i did you forget `aes(group = ...)`?
7+
Warning: Orientation is not uniquely specified when both the x and y aesthetics are continuous. Picking default orientation 'x'.
108

119
---
1210

13-
Continuous x aesthetic
14-
i did you forget `aes(group = ...)`?
11+
Warning: Orientation is not uniquely specified when both the x and y aesthetics are continuous. Picking default orientation 'x'.
1512

1613
# boxplots with a group size >1 error
1714

0 commit comments

Comments
 (0)