Skip to content

stricter test in find_x_overlaps() (#2615) #2616

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

Closed
wants to merge 1 commit into from

Conversation

cpsievert
Copy link
Contributor

No description provided.

@karawoo
Copy link
Member

karawoo commented May 16, 2018

Thanks for looking into this @cpsievert! With this fix the box plot succeeds silently, whereas in the CRAN version it succeeds with a warning. @hadley do you think we should try to keep the warning behavior?

library("ggplot2") # CRAN
ggplot(PlantGrowth, aes(x = group, y = weight)) + 
  geom_boxplot() +
  scale_x_discrete(limits = c("trt1", "ctrl"))
#> Warning: Removed 10 rows containing non-finite values (stat_boxplot).

Created on 2018-05-16 by the reprex package (v0.2.0).

@hadley
Copy link
Member

hadley commented May 16, 2018

I think we should try and fix the warning - I think that's probably an alternative to @cpsievert's solution - i.e. the missing values should be removed before we get to dodge2.

@karawoo
Copy link
Member

karawoo commented May 17, 2018

Actually I was wrong, with this PR there's a warning about 1 missing row, and that's in line with the behavior of position = "dodge" on master:

devtools::install_github("tidyverse/ggplot2", quiet = TRUE)
library("ggplot2")
ggplot(PlantGrowth, aes(x = group, y = weight)) + 
  geom_boxplot(position = "dodge") +
  scale_x_discrete(limits = c("trt1", "ctrl"))
#> Warning: Removed 1 rows containing missing values (geom_boxplot).

Created on 2018-05-16 by the reprex package (v0.2.0).

This is still a bit odd because there are 10 rows of data that are removed, but this change in behavior isn't related to find_x_overlaps() so I think we should merge this fix.

However it turns up another issue we need to address separately, which is that the widths of the boxes is messed up 😭:

devtools::install_github("cpsievert/ggplot2", ref = "fix_x_overlaps", quiet = TRUE)
library("ggplot2")
ggplot(PlantGrowth, aes(x = group, y = weight)) + 
  geom_boxplot() +
  scale_x_discrete(limits = c("trt1", "ctrl"))
#> Warning: Removed 1 rows containing missing values (geom_boxplot).

Created on 2018-05-16 by the reprex package (v0.2.0).

@hadley
Copy link
Member

hadley commented May 17, 2018

I'm not sure that the fix is correct - what should counter be if xmin or xmax is NA?

@karawoo
Copy link
Member

karawoo commented May 18, 2018

Looked into this some more and I propose we add

data <- remove_missing(data, na.rm = FALSE, vars = "x", name = "geom_boxplot")

here:

ggplot2/R/stat-boxplot.r

Lines 47 to 50 in 4b609fb

setup_data = function(data, params) {
data$x <- data$x %||% 0
data
},

Which results in:

  1. plot succeeds with a warning about 10 removed rows (not 1), for both versions of position dodge
  2. box widths are then correct (phew)

@hadley if you agree I can submit a PR and test tomorrow, unless @cpsievert wants to add it here instead.

@hadley
Copy link
Member

hadley commented May 18, 2018

Yes, that sounds perfect!

@hadley hadley closed this in 2a5e494 May 18, 2018
@lock
Copy link

lock bot commented Nov 14, 2018

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

@lock lock bot locked and limited conversation to collaborators Nov 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants