Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Fixed regression where `draw_key_rect()` stopped using `fill` colours
(@mitchelloharawild, #6609).
* Fixed regression where `scale_{x,y}_*()` threw an error when an expression
object is set to `labels` argument (@yutannihilation, #6617).
object is set to `labels` argument (@yutannihilation, #6617, #6638).


* Allow `stat` in `geom_hline`, `geom_vline`, and `geom_abline`. (@sierrajohnson, #6559)
Expand Down
6 changes: 3 additions & 3 deletions R/scale-.R
Original file line number Diff line number Diff line change
Expand Up @@ -1190,7 +1190,7 @@ ScaleContinuous <- ggproto("ScaleContinuous", Scale,
labels <- lapply(labels, `[`, 1)
}
if (is.expression(labels)) {
labels <- as.list(labels)
labels <- as.list(unclass(labels))
}

labels
Expand Down Expand Up @@ -1438,7 +1438,7 @@ ScaleDiscrete <- ggproto("ScaleDiscrete", Scale,
}

if (is.expression(labels)) {
labels <- as.list(labels)
labels <- as.list(unclass(labels))
}
labels
},
Expand Down Expand Up @@ -1689,7 +1689,7 @@ ScaleBinned <- ggproto("ScaleBinned", Scale,
)
}
if (is.expression(labels)) {
labels <- as.list(labels)
labels <- as.list(unclass(labels))
}
labels
},
Expand Down
10 changes: 7 additions & 3 deletions tests/testthat/test-scales-breaks-labels.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ test_that("labels don't have to match null breaks", {

test_that("labels accept expressions", {
labels <- parse(text = paste0(1:4, "^degree"))
sc <- scale_y_continuous(breaks = 1:4, labels = labels, limits = c(1, 3))
sc1 <- scale_y_continuous(breaks = 1:4, labels = labels, limits = c(1, 3))

expect_equal(sc$get_breaks(), 1:4)
expect_equal(sc$get_labels(), as.list(labels))
# classed labels should also work (#6638)
classed_labels <- structure(labels, class = "foo")
sc2 <- scale_y_continuous(breaks = 1:4, labels = classed_labels, limits = c(1, 3))

expect_equal(sc1$get_labels(), as.list(labels))
expect_equal(sc2$get_labels(), as.list(labels))
})

test_that("labels don't have extra spaces", {
Expand Down
Loading