Skip to content

Commit aaf3b4e

Browse files
committed
add test
1 parent c03f198 commit aaf3b4e

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

tests/testthat/test-theme.R

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,40 @@ test_that("complete_theme completes a theme", {
616616
reset_theme_settings()
617617
})
618618

619+
test_that("panel.widths and panel.heights works with free-space panels", {
620+
621+
df <- data.frame(x = c(1, 1, 2, 1, 3), g = c("A", "B", "B", "C", "C"))
622+
623+
p <- ggplotGrob(
624+
ggplot(df, aes(x, x)) +
625+
geom_point() +
626+
scale_x_continuous(expand = expansion(add = 1)) +
627+
facet_grid(~ g, scales = "free_x", space = "free_x") +
628+
theme(
629+
panel.widths = unit(11, "cm"),
630+
panel.spacing.x = unit(1, "cm")
631+
)
632+
)
633+
634+
idx <- range(panel_cols(p)$l)
635+
expect_equal(as.numeric(p$widths[seq(idx[1], idx[2])]), c(2, 1, 3, 1, 4))
636+
637+
p <- ggplotGrob(
638+
ggplot(df, aes(x, x)) +
639+
geom_point() +
640+
scale_y_continuous(expand = expansion(add = 1)) +
641+
facet_grid(g ~ ., scales = "free_y", space = "free_y") +
642+
theme(
643+
panel.heights = unit(11, "cm"),
644+
panel.spacing.y = unit(1, "cm")
645+
)
646+
)
647+
648+
idx <- range(panel_rows(p)$t)
649+
expect_equal(as.numeric(p$heights[seq(idx[1], idx[2])]), c(2, 1, 3, 1, 4))
650+
651+
})
652+
619653
# Visual tests ------------------------------------------------------------
620654

621655
test_that("aspect ratio is honored", {

0 commit comments

Comments
 (0)