Skip to content

Various fixes to orientation sniffing #3553

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion R/position-stack.r
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ PositionStack <- ggproto("PositionStack", Position,
vars = c("x", "xmin", "xmax", "y"),
name = "position_stack"
)
flip_data(data, params$flip_data)
flip_data(data, params$flipped_aes)
},

compute_panel = function(data, params, scales) {
Expand Down
14 changes: 11 additions & 3 deletions R/utilities.r
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,10 @@ has_flipped_aes <- function(data, params = list(), main_is_orthogonal = NA,
ambiguous = FALSE, main_is_continuous = FALSE) {
# Is orientation already encoded in data?
if (!is.null(data$flipped_aes)) {
return(data$flipped_aes[[1]])
not_na <- which(!is.na(data$flipped_aes))
if (length(not_na) != 0) {
return(data$flipped_aes[[not_na[1L]]])
}
}

# Is orientation requested in the params
Expand Down Expand Up @@ -583,12 +586,17 @@ has_flipped_aes <- function(data, params = list(), main_is_orthogonal = NA,
# If both are discrete like, which have most 0 or 1-spaced values
y_diff <- diff(sort(data$y))
x_diff <- diff(sort(data$x))

if (y_is_int && x_is_int) {
return((sum(x_diff <= 1) < sum(y_diff <= 1)) != main_is_continuous)
}

y_diff <- y_diff[y_diff != 0]
x_diff <- x_diff[x_diff != 0]

# If none are discrete is either regularly spaced
y_is_regular <- if (has_y) all((y_diff / min(y_diff)) %% 1 < .Machine$double.eps) else FALSE
x_is_regular <- if (has_x) all((x_diff / min(x_diff)) %% 1 < .Machine$double.eps) else FALSE
y_is_regular <- if (has_y && length(y_diff) != 0) all((y_diff / min(y_diff)) %% 1 < .Machine$double.eps) else FALSE
x_is_regular <- if (has_x && length(x_diff) != 0) all((x_diff / min(x_diff)) %% 1 < .Machine$double.eps) else FALSE
if (xor(y_is_regular, x_is_regular)) {
return(y_is_regular != main_is_continuous)
}
Expand Down