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

Inconsistent behaviour with geom_boxplot width #2777

Closed
dpseidel opened this issue Jul 26, 2018 · 3 comments
Closed

Inconsistent behaviour with geom_boxplot width #2777

dpseidel opened this issue Jul 26, 2018 · 3 comments

Comments

@dpseidel
Copy link
Collaborator

This bug was discovered as a part of fixing #2281 and initially discussed there. I am breaking this out into a separate issue.

In geom_boxplot() and associated geoms, width is typically a computed variable - not one often specified by the user. But in the original issue the poster specified width = 1 in their reprex, and as I was playing around fixing the resulting bug with scales::expand_range(), I noticed strange behaviour if width is ever set above 1. Specifically, when plotting multiple boxplots, it seems to no longer specify the width of each individual boxplot but instead the width of all plotted boxplots, resulting in axis ticks that don't line up.

Any thoughts on where this is coming from would be most appreciated. If I get time in the next couple weeks, I'll dig into this more.

Walk through reprex:

Default behavior, computed width, expected result:

library(ggplot2)
library(dplyr)

diamonds %>%
  ggplot(aes(clarity, price)) +
  geom_boxplot()

width set to 1. Individual boxplots get wider, each with a width of 1 now:

diamonds %>%
  ggplot(aes(clarity, price)) +
  geom_boxplot(width = 1)

width > 1, entire plot shrinks, axis ticks do not line up. All of the boxplots now fit within the designated width of 1.1.

diamonds %>%
  ggplot(aes(clarity, price)) +
  geom_boxplot(width = 1.1)

Any width value greater than 1 except 8 (the number of groups) will return a plot with misaligned labels.

Perhaps this is the expected behaviour of width and it's just acting unexpectedly for values ≤ 1 ? Or this is just a scales issue where we need to make sure our break points respect width alignment? Or maybe we shouldn't allow width specification at all?

@karawoo
Copy link
Member

karawoo commented Jul 26, 2018

There's been some previous discussion of this in #2331. We decided it was okay as-is, but if it keeps being an issue maybe we should revisit.

@dpseidel
Copy link
Collaborator Author

Oh thnx @karawoo! I didn't do a full search of closed issues.

Should we close this then?

@lock
Copy link

lock bot commented Jan 27, 2019

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 Jan 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants