Skip to content

Commit a5a1ce5

Browse files
committed
replace and remove redundant adjust_breaks() function
1 parent 79866e8 commit a5a1ce5

File tree

2 files changed

+4
-15
lines changed

2 files changed

+4
-15
lines changed

R/stat-bin2d.R

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ dual_param <- function(x, default = list(x = NULL, y = NULL)) {
104104
}
105105

106106
bin2d_breaks <- function(scale, breaks = NULL, origin = NULL, binwidth = NULL,
107-
bins = 30, right = TRUE) {
107+
bins = 30, closed = "right") {
108108
# Bins for categorical data should take the width of one level,
109109
# and should show up centered over their tick marks. All other parameters
110110
# are ignored.
@@ -138,18 +138,7 @@ bin2d_breaks <- function(scale, breaks = NULL, origin = NULL, binwidth = NULL,
138138
if (length(breaks) > 1 && breaks[length(breaks) - 1] >= range[2]) {
139139
breaks <- breaks[-length(breaks)]
140140
}
141-
142-
adjust_breaks(breaks, right)
143-
}
144-
145-
adjust_breaks <- function(x, right = TRUE) {
146-
diddle <- 1e-07 * stats::median(diff(x))
147-
if (right) {
148-
fuzz <- c(-diddle, rep.int(diddle, length(x) - 1))
149-
} else {
150-
fuzz <- c(rep.int(-diddle, length(x) - 1), diddle)
151-
}
152-
sort(x) + fuzz
141+
bins(breaks, closed)$fuzzy
153142
}
154143

155144
bin_loc <- function(x, id) {

tests/testthat/test-stat-bin2d.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ test_that("breaks override binwidth", {
3232
)
3333

3434
out <- get_layer_data(base)
35-
expect_equal(out$xbin, cut(df$x, adjust_breaks(integer_breaks), include.lowest = TRUE, labels = FALSE))
36-
expect_equal(out$ybin, cut(df$y, adjust_breaks(half_breaks), include.lowest = TRUE, labels = FALSE))
35+
expect_equal(out$xbin, cut(df$x, bins(integer_breaks)$fuzzy, include.lowest = TRUE, labels = FALSE))
36+
expect_equal(out$ybin, cut(df$y, bins(half_breaks)$fuzzy, include.lowest = TRUE, labels = FALSE))
3737
})
3838

3939
test_that("breaks are transformed by the scale", {

0 commit comments

Comments
 (0)