-
Notifications
You must be signed in to change notification settings - Fork 2.1k
stat_summary_bin gives 1 bin more than specified. #3824
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
Comments
Maybe the same issue? At least, I feel this needs some better documentation |
I highly doubt that floating point errors are a reason for a consistent off-by-one error. Especially since this is specific to that function and doesn't occur with |
This is a bug in |
we need to extend the range before we calculate the bin width but it is not obvious to me what the best approach is... Or maybe we should just add a small padding to the last bin so it includes the last data points? |
@thomasp85 thx for the pointer, didn't have time to dig deeper yet (the stack of function calls to weed through is massive to be honest...). fwiw,
Judging from the code of |
Thanks, I didn't notice this is such a problem... Here's a rendered version of reprex from #1739 library(ggplot2)
x <- seq(0, 1, length = 1e4)
y <- x + rnorm(length(x))
dt <- data.frame(x, y)
# NOT OK
ggplot(dt, aes(x, y)) +
geom_point(colour = "grey80") +
stat_summary_bin(fun = mean, bins = 10, geom = "point", colour = "red") Created on 2020-02-21 by the reprex package (v0.3.0) |
stat_summary_bin() consistently gives one more bin than specified in the function call
This shows 4 points. If you change bins to 4, it'll show 5 points and so on.
The text was updated successfully, but these errors were encountered: