Skip to content

Commit 8d5c69d

Browse files
committed
add test
1 parent 369079a commit 8d5c69d

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

tests/testthat/test-scales.R

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,3 +758,37 @@ test_that("discrete scales work with NAs in arbitrary positions", {
758758
expect_equal(test, output)
759759

760760
})
761+
762+
test_that("scale updating mechanism works", {
763+
p <- ggplot(mtcars, aes(disp, mpg, colour = factor(cyl), shape = factor(gear))) +
764+
geom_point(na.rm = TRUE)
765+
766+
scales <- get_panel_scales(
767+
p +
768+
scale_params("y", name = "Miles per gallon") +
769+
scale_params("y", limits = c(10, 40)) +
770+
scale_y_continuous(transform = "sqrt") +
771+
scale_params("y", expand = expansion())
772+
)
773+
y <- scales$y
774+
expect_equal(y$get_limits(), sqrt(c(10, 40)))
775+
expect_equal(y$expand, c(0, 0, 0, 0))
776+
expect_equal(y$name, "Miles per gallon")
777+
778+
b <- ggplot_build(
779+
p +
780+
scale_params("colour", labels = identity, breaks = c(8, 4, 6)) +
781+
scale_params(c("colour", "shape"), labels = function(x) as.character(as.roman(x))) +
782+
scale_params("shape", limits = as.character(c(3, 5)), labels = identity)
783+
)
784+
785+
# Roman label should override identity labels
786+
# Order should be unnatural
787+
l <- get_guide_data(b, "colour")
788+
expect_equal(l$.label, c("VIII", "IV", "VI"))
789+
790+
# Identity labels should override roman labels
791+
# gear = 4 should be missing from legend
792+
l <- get_guide_data(b, "shape")
793+
expect_equal(l$.label, as.character(c(3, 5)), ignore_attr = "pos")
794+
})

0 commit comments

Comments
 (0)