Skip to content

Commit 913e63a

Browse files
Allow expression labels in scale_{x,y}_*() (#6634)
* Add a failing test * Allow expression in size0() * Add a NEWS bullet
1 parent eece200 commit 913e63a

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
* Fixed regression where `draw_key_rect()` stopped using `fill` colours
66
(@mitchelloharawild, #6609).
7+
* Fixed regression where `scale_{x,y}_*()` threw an error when an expression
8+
object is set to `labels` argument (@yutannihilation, #6617).
79

810
# ggplot2 4.0.0
911

R/utilities.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ as_unordered_factor <- function(x) {
803803
size0 <- function(x) {
804804
if (obj_is_vector(x)) {
805805
vec_size(x)
806-
} else if (is.vector(x)) {
806+
} else if (is.vector(x) || is.expression(x)) {
807807
length(x)
808808
} else {
809809
NULL

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ test_that("labels don't have to match null breaks", {
1616
expect_silent(check_breaks_labels(breaks = NULL, labels = 1:2))
1717
})
1818

19+
test_that("labels accept expressions", {
20+
labels <- parse(text = paste0(1:4, "^degree"))
21+
sc <- scale_y_continuous(breaks = 1:4, labels = labels, limits = c(1, 3))
22+
23+
expect_equal(sc$get_breaks(), 1:4)
24+
expect_equal(sc$get_labels(), as.list(labels))
25+
})
26+
1927
test_that("labels don't have extra spaces", {
2028
labels <- c("a", "abc", "abcdef")
2129

0 commit comments

Comments
 (0)