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

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

Comments

Projects
None yet
3 participants

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))
Owner

hadley commented Jun 1, 2017

Can you please produce a reprex using the reprex package?

hadley added the reprex label Jun 1, 2017

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 layers and removed reprex labels Jun 22, 2017

Collaborator

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.

karawoo closed this in #2196 Jul 28, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment