Skip to content

Commit

Permalink
Fix binned scaled not accepting function-limits if there are transfor…
Browse files Browse the repository at this point in the history
…mations (#6145)

* fix bug

* add test

* add news bullet
  • Loading branch information
teunbrand authored Oct 28, 2024
1 parent fe26414 commit b174986
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# ggplot2 (development version)

* Fixed bug where binned scales wouldn't simultaneously accept transformations
and function-limits (@teunbrand, #6144).
* Fixed bug where the `ggplot2::`-prefix did not work with `stage()`
(@teunbrand, #6104).
* New `get_labs()` function for retrieving completed plot labels
Expand Down
2 changes: 1 addition & 1 deletion R/scale-.R
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ binned_scale <- function(aesthetics, scale_name = deprecated(), palette, name =
}

transform <- as.transform(transform)
if (!is.null(limits)) {
if (!is.null(limits) && !is.function(limits)) {
limits <- transform$transform(limits)
}

Expand Down
10 changes: 10 additions & 0 deletions tests/testthat/test-scale-binned.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ test_that("binned limits should not compute out-of-bounds breaks", {
))
})

test_that("binned scales can use limits and transformations simultaneously (#6144)", {
s <- scale_x_binned(
limits = function(x) x + 1,
trans = transform_log10()
)
s$train(c(0, 1)) # c(1, 10) in untransformed space
out <- s$get_limits()
expect_equal(s$get_limits(), log10(c(2, 11)))
})

test_that("binned scales can use NAs in limits", {
scale <- scale_x_binned(limits = c(NA, 10))
scale$train(c(-20, 20))
Expand Down

0 comments on commit b174986

Please sign in to comment.