Skip to content

Commit 66e37cb

Browse files
committed
add aspect ratio warning
1 parent 46ac6e0 commit 66e37cb

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

R/layout.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,14 @@ Layout <- ggproto("Layout", NULL,
309309
return(table)
310310
}
311311

312+
if (isTRUE(table$respect)) {
313+
args <- !c(is.null(new_widths), is.null(new_heights))
314+
args <- c("panel.widths", "panel.heights")[args]
315+
cli::cli_warn(
316+
"Aspect ratios are overruled by {.arg {args}} theme element{?s}."
317+
)
318+
}
319+
312320
rows <- panel_rows(table)
313321
cols <- panel_cols(table)
314322

tests/testthat/test-theme.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,13 @@ test_that("panel.widths and panel.heights works with free-space panels", {
650650

651651
})
652652

653+
test_that("panel.widths and panel.heights appropriately warn about aspect override", {
654+
p <- ggplot(mpg, aes(displ, hwy)) +
655+
geom_point() +
656+
theme(aspect.ratio = 1, panel.widths = unit(4, "cm"))
657+
expect_warning(ggplotGrob(p), "Aspect ratios are overruled")
658+
})
659+
653660
# Visual tests ------------------------------------------------------------
654661

655662
test_that("aspect ratio is honored", {

0 commit comments

Comments
 (0)