@@ -76,8 +76,8 @@ cut_width <- function(x, width, center = NULL, boundary = NULL, closed = "right"
76
76
}
77
77
boundary <- as.numeric(boundary )
78
78
79
- # Determine bins
80
- min_x <- find_origin( x_range , width , boundary )
79
+ # Determine bins, find origin
80
+ min_x <- boundary + floor(( x_range [ 1 ] - boundary ) / width ) * width
81
81
# Small correction factor so that we don't get an extra bin when, for
82
82
# example, origin = 0, max(x) = 20, width = 10.
83
83
max_x <- max(x , na.rm = TRUE ) + (1 - 1e-08 ) * width
@@ -86,12 +86,6 @@ cut_width <- function(x, width, center = NULL, boundary = NULL, closed = "right"
86
86
cut(x , breaks , include.lowest = TRUE , right = (closed == " right" ), ... )
87
87
}
88
88
89
- # Find the left side of left-most bin
90
- find_origin <- function (x_range , width , boundary ) {
91
- shift <- floor((x_range [1 ] - boundary ) / width )
92
- boundary + shift * width
93
- }
94
-
95
89
breaks <- function (x , equal , nbins = NULL , binwidth = NULL ) {
96
90
equal <- arg_match0(equal , c(" numbers" , " width" ))
97
91
if ((! is.null(nbins ) && ! is.null(binwidth )) || (is.null(nbins ) && is.null(binwidth ))) {
0 commit comments