From c1781e4952b0194530036ae7a478197c9c9c010f Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Fri, 18 Oct 2024 11:53:13 +0200 Subject: [PATCH 1/3] fix bug --- R/scale-.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/scale-.R b/R/scale-.R index 878cc602b9..bb56743bdb 100644 --- a/R/scale-.R +++ b/R/scale-.R @@ -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) } From e3c56ebe1280b1b3ee0fa3459f2302f71eba4a84 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Fri, 18 Oct 2024 11:53:18 +0200 Subject: [PATCH 2/3] add test --- tests/testthat/test-scale-binned.R | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/testthat/test-scale-binned.R b/tests/testthat/test-scale-binned.R index 31e32e9eba..1f558b6c77 100644 --- a/tests/testthat/test-scale-binned.R +++ b/tests/testthat/test-scale-binned.R @@ -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)) From 190e016f8bfcc44715855c3abe0eab4e01133c00 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Fri, 18 Oct 2024 11:54:24 +0200 Subject: [PATCH 3/3] add news bullet --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index f369879868..540e662f0c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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