Skip to content

geom_hex ignores binwidth argument when sample size is small #4580

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

Closed
sieste opened this issue Aug 9, 2021 · 1 comment · Fixed by #4671
Closed

geom_hex ignores binwidth argument when sample size is small #4580

sieste opened this issue Aug 9, 2021 · 1 comment · Fixed by #4671
Labels
bug an unexpected problem or unintended behavior layers 📈

Comments

@sieste
Copy link

sieste commented Aug 9, 2021

geom_hex ignores the binwidth argument when there are only few data points:

library(ggplot2)
n = 1
ggplot(tibble(x=rnorm(n), y=rnorm(n))) + 
  geom_hex(aes(x=x, y=y), binwidth=c(.1,.1)) + 
  xlim(-3, 3) + ylim(-3,3)

For small values of n (below 10) the bin widths are not 0.1. For larger n (try 100), the problem goes away and the bin width is 0.1 as specified.

@thomasp85
Copy link
Member

The issue here is when only a single bin exist in either dimension. The geom code calculates the resolution of the binning from the data itself and if there is only one bin it defaults to 1... we'll need to think about how to make this more sensible

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 layers 📈
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants