Skip to content

Commit e2e343f

Browse files
committed
fix failure with censored breaks when labels were specified manually
1 parent f16f16f commit e2e343f

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

R/guides-axis.r

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ guide_train.axis <- function(guide, scale, aesthetic = NULL) {
9393
}
9494
}
9595

96-
guide$key <- ticks
96+
guide$key <- ticks[is.finite(ticks[[aesthetic]]), ]
9797
}
9898

9999
guide$name <- paste0(guide$name, "_", aesthetic)

R/scale-view.r

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ view_scale_primary <- function(scale, limits = scale$get_limits(),
1717

1818
if(!scale$is_discrete()) {
1919
breaks <- scale$get_breaks(continuous_range)
20-
breaks <- breaks[is.finite(breaks)]
2120
minor_breaks <- scale$get_breaks_minor(b = breaks, limits = continuous_range)
2221
} else {
2322
breaks <- scale$get_breaks(limits)

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

+16
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,22 @@ test_that("continuous limits accepts functions", {
247247
expect_equal(layer_scales(p)$y$get_limits(), c(range(mpg$hwy)[1] - 10, range(mpg$hwy)[2] + 100))
248248
})
249249

250+
test_that("equal length breaks and labels can be passed to ViewScales with limits", {
251+
252+
test_scale <- scale_x_continuous(
253+
breaks = c(0, 20, 40),
254+
labels = c("0", "20", "40"),
255+
limits = c(10, 30)
256+
)
257+
258+
expect_identical(test_scale$get_breaks(), c(NA, 20, NA))
259+
expect_identical(test_scale$get_labels(), c(c("0", "20", "40")))
260+
261+
test_view_scale <- view_scale_primary(test_scale)
262+
expect_identical(test_view_scale$get_breaks(), c(NA, 20, NA))
263+
expect_identical(test_scale$get_labels(), c(c("0", "20", "40")))
264+
})
265+
250266
# Visual tests ------------------------------------------------------------
251267

252268
test_that("minor breaks draw correctly", {

0 commit comments

Comments
 (0)