Skip to content

Commit b174986

Browse files
authored
Fix binned scaled not accepting function-limits if there are transformations (#6145)
* fix bug * add test * add news bullet
1 parent fe26414 commit b174986

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

NEWS.md

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

3+
* Fixed bug where binned scales wouldn't simultaneously accept transformations
4+
and function-limits (@teunbrand, #6144).
35
* Fixed bug where the `ggplot2::`-prefix did not work with `stage()`
46
(@teunbrand, #6104).
57
* New `get_labs()` function for retrieving completed plot labels

R/scale-.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ binned_scale <- function(aesthetics, scale_name = deprecated(), palette, name =
319319
}
320320

321321
transform <- as.transform(transform)
322-
if (!is.null(limits)) {
322+
if (!is.null(limits) && !is.function(limits)) {
323323
limits <- transform$transform(limits)
324324
}
325325

tests/testthat/test-scale-binned.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ test_that("binned limits should not compute out-of-bounds breaks", {
4444
))
4545
})
4646

47+
test_that("binned scales can use limits and transformations simultaneously (#6144)", {
48+
s <- scale_x_binned(
49+
limits = function(x) x + 1,
50+
trans = transform_log10()
51+
)
52+
s$train(c(0, 1)) # c(1, 10) in untransformed space
53+
out <- s$get_limits()
54+
expect_equal(s$get_limits(), log10(c(2, 11)))
55+
})
56+
4757
test_that("binned scales can use NAs in limits", {
4858
scale <- scale_x_binned(limits = c(NA, 10))
4959
scale$train(c(-20, 20))

0 commit comments

Comments
 (0)