Skip to content

Commit e1fa690

Browse files
committed
add test for behaviour
1 parent cd001d7 commit e1fa690

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/testthat/test-theme.R

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,36 @@ test_that("panel.widths and panel.heights works with free-space panels", {
717717

718718
})
719719

720+
test_that("panel.withs and panel.heights preserve aspect ratios with single panels", {
721+
722+
df <- data.frame(x = c(1, 2))
723+
724+
p <- ggplotGrob(
725+
ggplot(df, aes(x, x)) +
726+
geom_point() +
727+
theme(
728+
aspect.ratio = 2,
729+
panel.heights = unit(10, "cm")
730+
)
731+
)
732+
733+
width <- p$widths[panel_cols(p)$l]
734+
expect_equal(as.character(width), "5cm")
735+
736+
p <- ggplotGrob(
737+
ggplot(df, aes(x, x)) +
738+
geom_point() +
739+
facet_wrap(~ x) + # This behaviour doesn't occur in multipanel plots.
740+
theme(
741+
aspect.ratio = 2,
742+
panel.heights = unit(10, "cm")
743+
)
744+
)
745+
746+
width <- p$widths[panel_cols(p)$l]
747+
expect_equal(as.character(width), c("1null", "1null"))
748+
})
749+
720750
test_that("margin_part() mechanics work as expected", {
721751

722752
t <- theme_gray() +

0 commit comments

Comments
 (0)