Skip to content

Fix single value detection in has_flipped_aes() - #3764

Closed
yutannihilation wants to merge 1 commit into
tidyverse:v3.3.0-rcfrom
yutannihilation:refactor/has-flipped-aes-unique-value
Closed

yutannihilation wants to merge 1 commit into
tidyverse:v3.3.0-rcfrom
yutannihilation:refactor/has-flipped-aes-unique-value

Conversation

@yutannihilation

@yutannihilation yutannihilation commented Jan 29, 2020 •

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

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

@yutannihilation

Copy link
Copy Markdown
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
Copy Markdown
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