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

geom_bin_2d() should recognise 0-width data #6207

Open
teunbrand opened this issue Nov 27, 2024 · 1 comment · May be fixed by #6212
Open

geom_bin_2d() should recognise 0-width data #6207

teunbrand opened this issue Nov 27, 2024 · 1 comment · May be fixed by #6212
Labels
bug an unexpected problem or unintended behavior

Comments

@teunbrand
Copy link
Collaborator

In the example below, the computation goes wrong because in the y-direction we don't have any width.

library(ggplot2)
df <- data.frame(x = 1:5, y = 1)

ggplot(df, aes(x, y)) +
  geom_bin_2d()
#> Warning: Computation failed in `stat_bin2d()`.
#> Caused by error in `bin2d_breaks()` at ggplot2/R/stat-bin2d.R:64:5:
#> ! `origin` must be a number, not `NaN`.

Created on 2024-11-27 with reprex v2.1.1

I think the reasonable thing to do in such a case is to choose 1 bin for the y-direction with 1 width.

@teunbrand
Copy link
Collaborator Author

Seems to apply more broadly to any 2D binning:

library(ggplot2)
df <- data.frame(x = 1:5, y = 1, z = 5)

ggplot(df, aes(x, y, z = z)) +
  stat_summary_2d()
#> Warning: Computation failed in `stat_summary2d()`.
#> Caused by error in `bin2d_breaks()` at ggplot2/R/stat-summary-2d.R:104:5:
#> ! `origin` must be a number, not `NaN`.

Created on 2024-11-28 with reprex v2.1.1

@teunbrand teunbrand added the bug an unexpected problem or unintended behavior label Dec 2, 2024
@teunbrand teunbrand linked a pull request Dec 4, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant