@@ -512,20 +512,27 @@ has_flipped_aes <- function(data, params = list(), main_is_orthogonal = NA,
512
512
return (params $ orientation == " y" )
513
513
}
514
514
515
+ x <- data $ x %|| % params $ x
516
+ y <- data $ y %|| % params $ y
517
+ xmin <- data $ xmin %|| % params $ xmin
518
+ ymin <- data $ ymin %|| % params $ ymin
519
+ xmax <- data $ xmax %|| % params $ xmax
520
+ ymax <- data $ ymax %|| % params $ ymax
521
+
515
522
# Does a single x or y aesthetic corespond to a specific orientation
516
- if (! is.na(main_is_orthogonal ) && sum(c( " x " , " y " ) %in% names( data )) + sum(c( " x " , " y " ) %in% names( params )) == 1 ) {
517
- return (( " x " %in% names( data ) || " x " %in% names( params ) ) == main_is_orthogonal )
523
+ if (! is.na(main_is_orthogonal ) && xor(is.null( x ), is.null( y )) ) {
524
+ return (is.null( y ) == main_is_orthogonal )
518
525
}
519
526
520
- has_x <- ! is.null(data $ x )
521
- has_y <- ! is.null(data $ y )
527
+ has_x <- ! is.null(x )
528
+ has_y <- ! is.null(y )
522
529
523
530
# Does a provided range indicate an orientation
524
531
if (! is.na(range_is_orthogonal )) {
525
- if (any(c( " ymin" , " ymax " ) %in% names( data ) )) {
532
+ if (! is.null( ymin ) || ! is.null( ymax )) {
526
533
return (! range_is_orthogonal )
527
534
}
528
- if (any(c( " xmin" , " xmax " ) %in% names( data ) )) {
535
+ if (! is.null( xmin ) || ! is.null( xmax )) {
529
536
return (range_is_orthogonal )
530
537
}
531
538
}
@@ -536,21 +543,23 @@ has_flipped_aes <- function(data, params = list(), main_is_orthogonal = NA,
536
543
}
537
544
538
545
# Is there a single actual discrete position
539
- y_is_int <- is.integer(data $ y )
540
- x_is_int <- is.integer(data $ x )
546
+ y_is_int <- is.integer(y )
547
+ x_is_int <- is.integer(x )
541
548
if (xor(y_is_int , x_is_int )) {
542
549
return (y_is_int != main_is_continuous )
543
550
}
544
551
545
552
# Does each group have a single x or y value
546
553
if (group_has_equal ) {
547
554
if (has_x ) {
555
+ if (length(x ) == 1 ) return (FALSE )
548
556
x_groups <- vapply(split(data $ x , data $ group ), function (x ) length(unique(x )), integer(1 ))
549
557
if (all(x_groups == 1 )) {
550
558
return (FALSE )
551
559
}
552
560
}
553
561
if (has_y ) {
562
+ if (length(y ) == 1 ) return (TRUE )
554
563
y_groups <- vapply(split(data $ y , data $ group ), function (x ) length(unique(x )), integer(1 ))
555
564
if (all(y_groups == 1 )) {
556
565
return (TRUE )
@@ -568,21 +577,21 @@ has_flipped_aes <- function(data, params = list(), main_is_orthogonal = NA,
568
577
return (FALSE )
569
578
}
570
579
# Is there a single discrete-like position
571
- y_is_int <- if (has_y ) isTRUE(all.equal(data $ y , round(data $ y ))) else FALSE
572
- x_is_int <- if (has_x ) isTRUE(all.equal(data $ x , round(data $ x ))) else FALSE
580
+ y_is_int <- if (has_y ) isTRUE(all.equal(y , round(y ))) else FALSE
581
+ x_is_int <- if (has_x ) isTRUE(all.equal(x , round(x ))) else FALSE
573
582
if (xor(y_is_int , x_is_int )) {
574
583
return (y_is_int != main_is_continuous )
575
584
}
576
585
# Is one of the axes a single value
577
- if (all(data $ x == 1 )) {
586
+ if (all(x == 1 )) {
578
587
return (main_is_continuous )
579
588
}
580
- if (all(data $ y == 1 )) {
589
+ if (all(y == 1 )) {
581
590
return (! main_is_continuous )
582
591
}
583
592
# If both are discrete like, which have most 0 or 1-spaced values
584
- y_diff <- diff(sort(data $ y ))
585
- x_diff <- diff(sort(data $ x ))
593
+ y_diff <- diff(sort(y ))
594
+ x_diff <- diff(sort(x ))
586
595
587
596
if (y_is_int && x_is_int ) {
588
597
return ((sum(x_diff < = 1 ) < sum(y_diff < = 1 )) != main_is_continuous )
0 commit comments