ggstat
ggstat copied to clipboard
Add option for "impartial binning" for histograms
From @rpruim on July 26, 2016 12:40
Traditionally (i.e., in hist()
) one must choose between left-leaning and right-leaning binning with right = FALSE
or right = TRUE
. A more balanced option would be to allow right = 0.5
. Under this option, data values exactly on a bin border would count has 0.5 in the bin to the left and 0.5 in the bin to the right.
Naive implementation is easy:
newcounts <-
right * hist(..., right = TRUE)$counts +
(1 - right) * hist(..., right = FALSE)$counts
This would work for other values of right
a well, although it is less clear that other values are useful. Setting right = TRUE
or right = FALSE
still works as before (although less efficiently).
Copied from original issue: hadley/ggplot2#1680