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

Unexpected error about center/boundary in geom_histogram() when bins = 1 #5890

Closed
teunbrand opened this issue May 13, 2024 · 0 comments · Fixed by #5891
Closed

Unexpected error about center/boundary in geom_histogram() when bins = 1 #5890

teunbrand opened this issue May 13, 2024 · 0 comments · Fixed by #5891

Comments

@teunbrand
Copy link
Collaborator

The following error is confusing, as we haven't specified any boundary:

library(ggplot2)

ggplot(mpg, aes(displ)) +
  geom_histogram(bins = 1, center = 0)
#> Warning: Computation failed in `stat_bin()`.
#> Caused by error in `bin_breaks_width()`:
#> ! Only one of `boundary` and `center` may be specified.

Inversely, when using the boundary argument, no such error is raised.

ggplot(mpg, aes(displ)) +
  geom_histogram(bins = 1, boundary = 0)

Created on 2024-05-13 with reprex v2.1.0

I think it is due to this line that populates a boundary argument, which then conflicts with center.

ggplot2/R/bin.R

Lines 117 to 120 in 54cbb98

} else if (bins == 1) {
width <- diff(x_range)
boundary <- x_range[1]
} else {

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 a pull request may close this issue.

1 participant