Skip to content

Commit ff7f269

Browse files
committed
Merge pull request #1209 from krlmlr/871-transformed-breaks
Fix automatically computed breaks for "probit" scale
2 parents 2629b53 + 7b1a5fb commit ff7f269

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,9 @@ ggplot2 1.0.1.9xxx
243243
aesthetics (e.g. `aes(sapply(..density.., function(x) mean(x))))`
244244
(#1154, @NikNakk)
245245

246+
* Automatically computed breaks do not lead to an error for transformations like
247+
"probit" where the inverse can map to infinity (#871, @krlmlr)
248+
246249
ggplot2 1.0.1
247250
----------------------------------------------------------------
248251

R/scale-.r

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,8 @@ scale_breaks.continuous <- function(scale, limits = scale_limits(scale)) {
383383
# @kohske
384384
# TODO: replace NA with something else for flag.
385385
# guides cannot discriminate oob from missing value.
386-
breaks <- censor(scale$trans$transform(breaks), scale$trans$transform(limits))
386+
breaks <- censor(scale$trans$transform(breaks), scale$trans$transform(limits),
387+
only.finite = FALSE)
387388
if (length(breaks) == 0) {
388389
stop("Zero breaks in scale for ", paste(scale$aesthetics, collapse = "/"),
389390
call. = FALSE)

tests/testthat/test-scales-breaks-labels.r

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ test_that("labels match breaks, even when outside limits", {
77
expect_equal(scale_labels(sc), 1:4)
88
expect_equal(scale_breaks_minor(sc), c(1, 1.5, 2, 2.5, 3))
99
})
10-
.
1110

1211
test_that("labels must match breaks", {
1312
expect_that(scale_x_discrete(breaks = 1:3, labels = 1:2),
@@ -236,3 +235,10 @@ test_that("breaks can be specified by names of labels", {
236235
expect_equal(as.vector(scale_labels(s)), LETTERS[1:3])
237236

238237
})
238+
239+
test_that("only finite or NA values for breaks for transformed scales (#871)", {
240+
sc <- scale_y_continuous(limits = c(0.01, 0.99), trans = "probit",
241+
breaks = seq(0, 1, 0.2))
242+
breaks <- scale_breaks(sc)
243+
expect_true(all(is.finite(breaks) | is.na(breaks)))
244+
})

0 commit comments

Comments
 (0)