Skip to content

Commit bfe4b1c

Browse files
authored
Merge pull request #5074 from teunbrand/binned_zerorange
zero-range limits in binned scale
2 parents 44af941 + 0de8338 commit bfe4b1c

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

NEWS.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# ggplot2 (development version)
22

3+
* `scale_*_binned()` handles zero-range limits more gracefully (@teunbrand,
4+
#5066)
35
* Binned scales are now compatible with `trans = "date"` and `trans = "time"`
46
(@teunbrand, #4217).
57
* `ggsave()` warns when multiple `filename`s are given, and only writes to the
@@ -12,7 +14,7 @@
1214
(@teunbrand based on @clauswilke's suggestion #5051).
1315
* Fixed a regression in `Coord$train_panel_guides()` where names of guides were
1416
dropped (@maxsutton, #5063)
15-
17+
1618
# ggplot2 3.4.0
1719
This is a minor release focusing on tightening up the internals and ironing out
1820
some inconsistencies in the API. The biggest change is the addition of the

R/scale-.r

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,16 +1021,22 @@ ScaleBinned <- ggproto("ScaleBinned", Scale,
10211021
x <- self$rescale(self$oob(x, range = limits), limits)
10221022
breaks <- self$rescale(breaks, limits)
10231023

1024-
x_binned <- cut(x, breaks,
1025-
labels = FALSE,
1026-
include.lowest = TRUE,
1027-
right = self$right
1028-
)
1024+
if (length(breaks) > 1) {
1025+
x_binned <- cut(x, breaks,
1026+
labels = FALSE,
1027+
include.lowest = TRUE,
1028+
right = self$right
1029+
)
1030+
midpoints <- breaks[-1] - diff(breaks) / 2
1031+
} else {
1032+
x_binned <- 1L
1033+
midpoints <- 0.5
1034+
}
10291035

10301036
if (!is.null(self$palette.cache)) {
10311037
pal <- self$palette.cache
10321038
} else {
1033-
pal <- self$palette(breaks[-1] - diff(breaks) / 2)
1039+
pal <- self$palette(midpoints)
10341040
self$palette.cache <- pal
10351041
}
10361042

0 commit comments

Comments
 (0)