Skip to content

Fix single value detection in has_flipped_aes() #3764

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

Conversation

yutannihilation
Copy link
Member

@yutannihilation yutannihilation commented Jan 29, 2020

These lines are to detect the case "the axes is a single value," but, in actual, they check whether all values are a fixed value1 or not.

ggplot2/R/utilities.r

Lines 594 to 600 in 5e6b1e5

# Is one of the axes a single value
if (all(x == 1)) {
return(main_is_continuous)
}
if (all(y == 1)) {
return(!main_is_continuous)
}

This causes different behaviours between the case of 1 and that of another value. This PR fixes the check to zero_range(range()).

library(ggplot2)

df <- data.frame(value = 1:3, group = c("a", "a", "b"))
l <-  stat_summary(fun = "mean", geom = "bar", position = "dodge")
p1 <- ggplot(df, aes(value, 1, fill = group)) + l
p2 <- ggplot(df, aes(value, 0, fill = group)) + l

patchwork::wrap_plots(p1, p2, ncol = 1)

Created on 2020-01-29 by the reprex package (v0.3.0)

@thomasp85
Copy link
Member

The I tend of that check is really to catch when boxplots are created with no x-aesthetic at which point they’ll get a 1 automatically. I’ll have to think about the repercussions of this change a bit and whether it is the right way to go about it

@yutannihilation
Copy link
Member Author

Got it, thanks for the context. Then, if this requires some time to consider, should I close this and resend against the master? This pull request is just that I was not immediately sure what the comment says.

@thomasp85
Copy link
Member

Your reprex suggest that the check is too eager, not the other way around... I'll experiment a bit

@yutannihilation
Copy link
Member Author

Your reprex suggest

To be clear, my reprex in the description shows the problematic behaviour of the current RC version. Sorry if it's confusing.

@thomasp85
Copy link
Member

Closing in favour of #3800

@thomasp85 thomasp85 closed this Feb 6, 2020
@yutannihilation yutannihilation deleted the refactor/has-flipped-aes-unique-value branch February 6, 2020 10:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants