@@ -504,7 +504,10 @@ has_flipped_aes <- function(data, params = list(), main_is_orthogonal = NA,
504
504
ambiguous = FALSE , main_is_continuous = FALSE ) {
505
505
# Is orientation already encoded in data?
506
506
if (! is.null(data $ flipped_aes )) {
507
- return (data $ flipped_aes [[1 ]])
507
+ not_na <- which(! is.na(data $ flipped_aes ))
508
+ if (length(not_na ) != 0 ) {
509
+ return (data $ flipped_aes [[not_na [1L ]]])
510
+ }
508
511
}
509
512
510
513
# Is orientation requested in the params
@@ -583,12 +586,17 @@ has_flipped_aes <- function(data, params = list(), main_is_orthogonal = NA,
583
586
# If both are discrete like, which have most 0 or 1-spaced values
584
587
y_diff <- diff(sort(data $ y ))
585
588
x_diff <- diff(sort(data $ x ))
589
+
586
590
if (y_is_int && x_is_int ) {
587
591
return ((sum(x_diff < = 1 ) < sum(y_diff < = 1 )) != main_is_continuous )
588
592
}
593
+
594
+ y_diff <- y_diff [y_diff != 0 ]
595
+ x_diff <- x_diff [x_diff != 0 ]
596
+
589
597
# If none are discrete is either regularly spaced
590
- y_is_regular <- if (has_y ) all((y_diff / min(y_diff )) %% 1 < .Machine $ double.eps ) else FALSE
591
- x_is_regular <- if (has_x ) all((x_diff / min(x_diff )) %% 1 < .Machine $ double.eps ) else FALSE
598
+ y_is_regular <- if (has_y && length( y_diff ) != 0 ) all((y_diff / min(y_diff )) %% 1 < .Machine $ double.eps ) else FALSE
599
+ x_is_regular <- if (has_x && length( x_diff ) != 0 ) all((x_diff / min(x_diff )) %% 1 < .Machine $ double.eps ) else FALSE
592
600
if (xor(y_is_regular , x_is_regular )) {
593
601
return (y_is_regular != main_is_continuous )
594
602
}
0 commit comments