@@ -475,6 +475,10 @@ switch_orientation <- function(aesthetics) {
475
475
# ' will be the discrete-like one. Examples of `TRUE` is [stat_density()] and
476
476
# ' [stat_bin()], while examples of `FALSE` is [stat_ydensity()] and
477
477
# ' [stat_boxplot()]
478
+ # ' - `main_is_optional`: This argument controls the rare case of layers were the
479
+ # ' main direction is an optional aesthetic. This is only seen in
480
+ # ' [stat_boxplot()] where `x` is set to `0` if not given. If `TRUE` there will
481
+ # ' be a check for whether all `x` or all `y` are equal to `0`
478
482
# '
479
483
# ' @param data The layer data
480
484
# ' @param params The parameters of the `Stat`/`Geom`. Only the `orientation`
@@ -491,6 +495,8 @@ switch_orientation <- function(aesthetics) {
491
495
# ' will only be flipped if `params$orientation == "y"`
492
496
# ' @param main_is_continuous If there is a discrete and continuous axis, does
493
497
# ' the continuous one correspond to the main orientation?
498
+ # ' @param main_is_optional Is the main axis aesthetic optional and, if not
499
+ # ' given, set to `0`
494
500
# ' @param flip Logical. Is the layer flipped.
495
501
# '
496
502
# ' @return `has_flipped_aes()` returns `TRUE` if it detects a layer in the other
@@ -507,7 +513,8 @@ switch_orientation <- function(aesthetics) {
507
513
# '
508
514
has_flipped_aes <- function (data , params = list (), main_is_orthogonal = NA ,
509
515
range_is_orthogonal = NA , group_has_equal = FALSE ,
510
- ambiguous = FALSE , main_is_continuous = FALSE ) {
516
+ ambiguous = FALSE , main_is_continuous = FALSE ,
517
+ main_is_optional = FALSE ) {
511
518
# Is orientation already encoded in data?
512
519
if (! is.null(data $ flipped_aes )) {
513
520
not_na <- which(! is.na(data $ flipped_aes ))
@@ -591,12 +598,15 @@ has_flipped_aes <- function(data, params = list(), main_is_orthogonal = NA,
591
598
if (xor(y_is_int , x_is_int )) {
592
599
return (y_is_int != main_is_continuous )
593
600
}
594
- # Is one of the axes a single value
595
- if (all(x == 1 )) {
596
- return (main_is_continuous )
597
- }
598
- if (all(y == 1 )) {
599
- return (! main_is_continuous )
601
+
602
+ if (main_is_optional ) {
603
+ # Is one of the axes all 0
604
+ if (all(x == 0 )) {
605
+ return (main_is_continuous )
606
+ }
607
+ if (all(y == 0 )) {
608
+ return (! main_is_continuous )
609
+ }
600
610
}
601
611
602
612
y_diff <- diff(sort(y ))
0 commit comments