Skip to content

Commit

Permalink
Merge pull request #5074 from teunbrand/binned_zerorange
Browse files Browse the repository at this point in the history
zero-range limits in binned scale
  • Loading branch information
teunbrand authored Jan 6, 2023
2 parents 44af941 + 0de8338 commit bfe4b1c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
4 changes: 3 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# ggplot2 (development version)

* `scale_*_binned()` handles zero-range limits more gracefully (@teunbrand,
#5066)
* Binned scales are now compatible with `trans = "date"` and `trans = "time"`
(@teunbrand, #4217).
* `ggsave()` warns when multiple `filename`s are given, and only writes to the
Expand All @@ -12,7 +14,7 @@
(@teunbrand based on @clauswilke's suggestion #5051).
* Fixed a regression in `Coord$train_panel_guides()` where names of guides were
dropped (@maxsutton, #5063)

# ggplot2 3.4.0
This is a minor release focusing on tightening up the internals and ironing out
some inconsistencies in the API. The biggest change is the addition of the
Expand Down
18 changes: 12 additions & 6 deletions R/scale-.r
Original file line number Diff line number Diff line change
Expand Up @@ -1021,16 +1021,22 @@ ScaleBinned <- ggproto("ScaleBinned", Scale,
x <- self$rescale(self$oob(x, range = limits), limits)
breaks <- self$rescale(breaks, limits)

x_binned <- cut(x, breaks,
labels = FALSE,
include.lowest = TRUE,
right = self$right
)
if (length(breaks) > 1) {
x_binned <- cut(x, breaks,
labels = FALSE,
include.lowest = TRUE,
right = self$right
)
midpoints <- breaks[-1] - diff(breaks) / 2
} else {
x_binned <- 1L
midpoints <- 0.5
}

if (!is.null(self$palette.cache)) {
pal <- self$palette.cache
} else {
pal <- self$palette(breaks[-1] - diff(breaks) / 2)
pal <- self$palette(midpoints)
self$palette.cache <- pal
}

Expand Down

0 comments on commit bfe4b1c

Please sign in to comment.