@@ -512,20 +512,27 @@ has_flipped_aes <- function(data, params = list(), main_is_orthogonal = NA,
512512 return (params $ orientation == " y" )
513513 }
514514
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+
515522 # 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 )
518525 }
519526
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 )
522529
523530 # Does a provided range indicate an orientation
524531 if (! is.na(range_is_orthogonal )) {
525- if (any(c( " ymin" , " ymax " ) %in% names( data ) )) {
532+ if (! is.null( ymin ) || ! is.null( ymax )) {
526533 return (! range_is_orthogonal )
527534 }
528- if (any(c( " xmin" , " xmax " ) %in% names( data ) )) {
535+ if (! is.null( xmin ) || ! is.null( xmax )) {
529536 return (range_is_orthogonal )
530537 }
531538 }
@@ -536,21 +543,23 @@ has_flipped_aes <- function(data, params = list(), main_is_orthogonal = NA,
536543 }
537544
538545 # 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 )
541548 if (xor(y_is_int , x_is_int )) {
542549 return (y_is_int != main_is_continuous )
543550 }
544551
545552 # Does each group have a single x or y value
546553 if (group_has_equal ) {
547554 if (has_x ) {
555+ if (length(x ) == 1 ) return (FALSE )
548556 x_groups <- vapply(split(data $ x , data $ group ), function (x ) length(unique(x )), integer(1 ))
549557 if (all(x_groups == 1 )) {
550558 return (FALSE )
551559 }
552560 }
553561 if (has_y ) {
562+ if (length(y ) == 1 ) return (TRUE )
554563 y_groups <- vapply(split(data $ y , data $ group ), function (x ) length(unique(x )), integer(1 ))
555564 if (all(y_groups == 1 )) {
556565 return (TRUE )
@@ -568,21 +577,21 @@ has_flipped_aes <- function(data, params = list(), main_is_orthogonal = NA,
568577 return (FALSE )
569578 }
570579 # 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
573582 if (xor(y_is_int , x_is_int )) {
574583 return (y_is_int != main_is_continuous )
575584 }
576585 # Is one of the axes a single value
577- if (all(data $ x == 1 )) {
586+ if (all(x == 1 )) {
578587 return (main_is_continuous )
579588 }
580- if (all(data $ y == 1 )) {
589+ if (all(y == 1 )) {
581590 return (! main_is_continuous )
582591 }
583592 # 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 ))
586595
587596 if (y_is_int && x_is_int ) {
588597 return ((sum(x_diff < = 1 ) < sum(y_diff < = 1 )) != main_is_continuous )
0 commit comments