File tree 3 files changed +14
-2
lines changed
3 files changed +14
-2
lines changed Original file line number Diff line number Diff line change 8
8
* Fixed spurious warnings from ` sec_axis() ` with ` breaks = NULL ` (#5713 ).
9
9
* Patterns and gradients are now also enabled in ` geom_sf() `
10
10
(@teunbrand , #5716 ).
11
+ * ` stat_bin() ` deals with non-finite breaks better (@teunbrand , #5665 ).
11
12
12
13
# ggplot2 3.5.0
13
14
Original file line number Diff line number Diff line change 1
1
bins <- function (breaks , closed = " right" ,
2
- fuzz = 1e-08 * stats :: median(diff( breaks )) ) {
2
+ fuzz = NULL ) {
3
3
check_numeric(breaks )
4
4
closed <- arg_match0(closed , c(" right" , " left" ))
5
-
6
5
breaks <- sort(breaks )
6
+
7
7
# Adapted base::hist - this protects from floating point rounding errors
8
+ fuzz <- fuzz %|| % 1e-08 * stats :: median(diff(breaks [is.finite(breaks )]))
9
+ if (! is.finite(fuzz )) { # happens when 0 or 1 finite breaks are given
10
+ fuzz <- .Machine $ double.eps * 1e3
11
+ }
8
12
if (closed == " right" ) {
9
13
fuzzes <- c(- fuzz , rep.int(fuzz , length(breaks ) - 1 ))
10
14
} else {
Original file line number Diff line number Diff line change @@ -112,6 +112,13 @@ test_that("stat_bin() provides width (#3522)", {
112
112
113
113
# Underlying binning algorithm --------------------------------------------
114
114
115
+ test_that(" bins() computes fuzz with non-finite breaks" , {
116
+ test <- bins(breaks = c(- Inf , 1 , Inf ))
117
+ expect_equal(test $ fuzzy , test $ breaks , tolerance = 1e-10 )
118
+ difference <- test $ fuzzy - test $ breaks
119
+ expect_equal(difference [2 ], 1000 * .Machine $ double.eps , tolerance = 0 )
120
+ })
121
+
115
122
comp_bin <- function (df , ... ) {
116
123
plot <- ggplot(df , aes(x = x )) + stat_bin(... )
117
124
layer_data(plot )
You can’t perform that action at this time.
0 commit comments