Skip to content

Commit 9b667b9

Browse files
authored
Various fixes to orientation sniffing (#3553)
1 parent a2ab197 commit 9b667b9

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

R/position-stack.r

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ PositionStack <- ggproto("PositionStack", Position,
173173
vars = c("x", "xmin", "xmax", "y"),
174174
name = "position_stack"
175175
)
176-
flip_data(data, params$flip_data)
176+
flip_data(data, params$flipped_aes)
177177
},
178178

179179
compute_panel = function(data, params, scales) {

R/utilities.r

+11-3
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,10 @@ has_flipped_aes <- function(data, params = list(), main_is_orthogonal = NA,
504504
ambiguous = FALSE, main_is_continuous = FALSE) {
505505
# Is orientation already encoded in data?
506506
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+
}
508511
}
509512

510513
# Is orientation requested in the params
@@ -583,12 +586,17 @@ has_flipped_aes <- function(data, params = list(), main_is_orthogonal = NA,
583586
# If both are discrete like, which have most 0 or 1-spaced values
584587
y_diff <- diff(sort(data$y))
585588
x_diff <- diff(sort(data$x))
589+
586590
if (y_is_int && x_is_int) {
587591
return((sum(x_diff <= 1) < sum(y_diff <= 1)) != main_is_continuous)
588592
}
593+
594+
y_diff <- y_diff[y_diff != 0]
595+
x_diff <- x_diff[x_diff != 0]
596+
589597
# 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
592600
if (xor(y_is_regular, x_is_regular)) {
593601
return(y_is_regular != main_is_continuous)
594602
}

0 commit comments

Comments
 (0)