Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zero-range limits in binned scale #5074

Merged
merged 4 commits into from
Jan 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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