Skip to content

Commit c6181fd

Browse files
committed
add test
1 parent 6f8e22f commit c6181fd

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

tests/testthat/test-scales.R

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,3 +755,32 @@ test_that("discrete scales work with NAs in arbitrary positions", {
755755
expect_equal(test, output)
756756

757757
})
758+
759+
test_that("discrete scales can map to 2D structures", {
760+
761+
p <- ggplot(mtcars, aes(disp, mpg, colour = factor(cyl))) +
762+
geom_point()
763+
764+
# Test it can map to a vctrs rcrd class
765+
rcrd <- new_rcrd(list(a = LETTERS[1:3], b = 3:1))
766+
767+
ld <- layer_data(p + scale_colour_manual(values = rcrd, na.value = NA))
768+
expect_s3_class(ld$colour, "vctrs_rcrd")
769+
expect_length(ld$colour, nrow(mtcars))
770+
771+
# Test it can map to data.frames
772+
df <- data_frame0(a = LETTERS[1:3], b = 3:1)
773+
my_pal <- function(n) vec_slice(df, seq_len(n))
774+
775+
ld <- layer_data(p + discrete_scale("colour", palette = my_pal))
776+
expect_s3_class(ld$colour, "data.frame")
777+
expect_equal(dim(ld$colour), c(nrow(mtcars), ncol(df)))
778+
779+
# Test it can map to matrices
780+
mtx <- cbind(a = LETTERS[1:3], b = LETTERS[4:6])
781+
my_pal <- function(n) vec_slice(mtx, seq_len(n))
782+
783+
ld <- layer_data(p + discrete_scale("colour", palette = my_pal))
784+
expect_true(is.matrix(ld$colour))
785+
expect_equal(dim(ld$colour), c(nrow(mtcars), ncol(df)))
786+
})

0 commit comments

Comments
 (0)