Skip to content
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

overlapping boxes with geom_boxplot(varwidth=TRUE) #2143

Closed
mcol opened this issue May 25, 2017 · 3 comments
Closed

overlapping boxes with geom_boxplot(varwidth=TRUE) #2143

mcol opened this issue May 25, 2017 · 3 comments
Labels
bug an unexpected problem or unintended behavior layers 📈

Comments

@mcol
Copy link
Contributor

mcol commented May 25, 2017

When I try to produce boxplots with colours depending on a categorical variable, these appear overlapping if varwidth is set to TRUE (which is what I'd like to use).

Here's an example:

ggplot(data=iris, aes(Species, Sepal.Length)) + 
   geom_boxplot(aes(colour=Sepal.Width < 3.2), varwidth=TRUE)

This raises the following warning: "position_dodge requires non-overlapping x intervals"

However, the boxes don't overlap (and no warning is raised) if varwidth is not specified.

ggplot(data=iris, aes(Species, Sepal.Length)) + 
   geom_boxplot(aes(colour=Sepal.Width < 3.2))
@hadley
Copy link
Member

hadley commented Jun 1, 2017

Can you please produce a reprex using the reprex package?

@hadley hadley added the reprex needs a minimal reproducible example label Jun 1, 2017
@mcol
Copy link
Contributor Author

mcol commented Jun 2, 2017

require(ggplot2)
#> Loading required package: ggplot2
ggplot(data = iris, aes(Species, Sepal.Length)) + geom_boxplot(aes(colour = Sepal.Width < 
  3.2), varwidth = TRUE)
#> Warning: position_dodge requires non-overlapping x intervals

@karawoo karawoo added bug an unexpected problem or unintended behavior layers 📈 and removed reprex needs a minimal reproducible example labels Jun 22, 2017
@karawoo
Copy link
Member

karawoo commented Jun 30, 2017

The main problem is here — within each species the variable-width boxes have different xmin values, so pos_dodge() gets called on each box separately when it should be getting called on each pair of boxes.

I think this line will also be a problem because only the width of the first box will be used. pos_dodge() probably needs to be changed to handle multiple widths.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug an unexpected problem or unintended behavior layers 📈
Projects
None yet
Development

No branches or pull requests

3 participants