From bc5d63270706c7248675626b049b56f3338cad5c Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Mon, 24 Feb 2025 15:56:28 +0100 Subject: [PATCH 1/4] set paper backgrounds --- R/theme-defaults.R | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/R/theme-defaults.R b/R/theme-defaults.R index 7fe9742f5e..541ce592eb 100644 --- a/R/theme-defaults.R +++ b/R/theme-defaults.R @@ -472,7 +472,7 @@ theme_minimal <- function(base_size = 11, base_family = "", panel.background = element_blank(), panel.border = element_blank(), strip.background = element_blank(), - plot.background = element_blank(), + plot.background = element_rect(fill = paper, colour = NA), complete = TRUE ) @@ -553,7 +553,7 @@ theme_void <- function(base_size = 11, base_family = "", header_family = NULL, base_line_size = base_size / 22, base_rect_size = base_size / 22, - ink = "black", paper = "white") { + ink = "black", paper = alpha(ink, 0)) { half_line <- base_size / 2 # Only keep indispensable text: legend and plot titles @@ -621,6 +621,13 @@ theme_void <- function(base_size = 11, base_family = "", plot.tag.position = 'topleft', complete = TRUE + ) + theme( + # Contrary to default behaviour, we do not want to inherit the plot + # background from a blank root element + plot.background = element_rect( + fill = paper, colour = NA, linewidth = 0, linetype = 1, + inherit.blank = FALSE + ) ) # make sure all elements are set to NULL if not explicitly defined From f47465c48cecc1c4e7d0d9a67643e8bf70ed35f2 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Mon, 24 Feb 2025 16:03:33 +0100 Subject: [PATCH 2/4] accept invisible rectangles --- .../_snaps/geom-polygon/open-and-closed-munched-polygons.svg | 1 + tests/testthat/_snaps/guides/guide-custom-with-void-theme.svg | 1 + tests/testthat/_snaps/theme/theme-minimal-large.svg | 1 + tests/testthat/_snaps/theme/theme-minimal.svg | 1 + tests/testthat/_snaps/theme/theme-void-large.svg | 1 + tests/testthat/_snaps/theme/theme-void.svg | 1 + 6 files changed, 6 insertions(+) diff --git a/tests/testthat/_snaps/geom-polygon/open-and-closed-munched-polygons.svg b/tests/testthat/_snaps/geom-polygon/open-and-closed-munched-polygons.svg index 5080746f6c..f134915d5f 100644 --- a/tests/testthat/_snaps/geom-polygon/open-and-closed-munched-polygons.svg +++ b/tests/testthat/_snaps/geom-polygon/open-and-closed-munched-polygons.svg @@ -18,6 +18,7 @@ + diff --git a/tests/testthat/_snaps/guides/guide-custom-with-void-theme.svg b/tests/testthat/_snaps/guides/guide-custom-with-void-theme.svg index ac52f62280..12b96037a8 100644 --- a/tests/testthat/_snaps/guides/guide-custom-with-void-theme.svg +++ b/tests/testthat/_snaps/guides/guide-custom-with-void-theme.svg @@ -18,6 +18,7 @@ + diff --git a/tests/testthat/_snaps/theme/theme-minimal-large.svg b/tests/testthat/_snaps/theme/theme-minimal-large.svg index 8ec3b18625..1dc1caf61a 100644 --- a/tests/testthat/_snaps/theme/theme-minimal-large.svg +++ b/tests/testthat/_snaps/theme/theme-minimal-large.svg @@ -18,6 +18,7 @@ + diff --git a/tests/testthat/_snaps/theme/theme-minimal.svg b/tests/testthat/_snaps/theme/theme-minimal.svg index aa5fbe37d8..ce2799c95b 100644 --- a/tests/testthat/_snaps/theme/theme-minimal.svg +++ b/tests/testthat/_snaps/theme/theme-minimal.svg @@ -18,6 +18,7 @@ + diff --git a/tests/testthat/_snaps/theme/theme-void-large.svg b/tests/testthat/_snaps/theme/theme-void-large.svg index 8135cd36d3..58ac3525dd 100644 --- a/tests/testthat/_snaps/theme/theme-void-large.svg +++ b/tests/testthat/_snaps/theme/theme-void-large.svg @@ -18,6 +18,7 @@ + diff --git a/tests/testthat/_snaps/theme/theme-void.svg b/tests/testthat/_snaps/theme/theme-void.svg index b69c91ef30..e537f6bb9d 100644 --- a/tests/testthat/_snaps/theme/theme-void.svg +++ b/tests/testthat/_snaps/theme/theme-void.svg @@ -18,6 +18,7 @@ + From a2bad418e24984280eb11cc8fe2f440377f16997 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Mon, 24 Feb 2025 16:30:33 +0100 Subject: [PATCH 3/4] follow conventional inheritance to satisfy test --- R/theme-defaults.R | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/R/theme-defaults.R b/R/theme-defaults.R index 541ce592eb..38ea2d0d92 100644 --- a/R/theme-defaults.R +++ b/R/theme-defaults.R @@ -559,7 +559,10 @@ theme_void <- function(base_size = 11, base_family = "", # Only keep indispensable text: legend and plot titles t <- theme( line = element_blank(), - rect = element_blank(), + rect = element_rect( + fill = paper, colour = NA, linewidth = 0, linetype = 1, + inherit.blank = FALSE + ), polygon = element_blank(), point = element_blank(), text = element_text( @@ -591,12 +594,18 @@ theme_void <- function(base_size = 11, base_family = "", legend.box.margin = rel(0), legend.box.spacing = unit(0.2, "cm"), legend.ticks.length = rel(0.2), + legend.background = element_blank(), + legend.frame = element_blank(), + legend.box.background = element_blank(), strip.clip = "on", strip.text = element_text(size = rel(0.8)), strip.switch.pad.grid = rel(0.5), strip.switch.pad.wrap = rel(0.5), + strip.background = element_blank(), panel.ontop = FALSE, panel.spacing = NULL, + panel.background = element_blank(), + panel.border = element_blank(), plot.margin = rel(0), plot.title = element_text( size = rel(1.2), @@ -619,15 +628,9 @@ theme_void <- function(base_size = 11, base_family = "", hjust = 0.5, vjust = 0.5 ), plot.tag.position = 'topleft', + plot.background = element_rect(), complete = TRUE - ) + theme( - # Contrary to default behaviour, we do not want to inherit the plot - # background from a blank root element - plot.background = element_rect( - fill = paper, colour = NA, linewidth = 0, linetype = 1, - inherit.blank = FALSE - ) ) # make sure all elements are set to NULL if not explicitly defined From 71684deeb9c402eaedaf11dab5be0b57ce1174a4 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Mon, 24 Feb 2025 16:52:29 +0100 Subject: [PATCH 4/4] redocument --- man/ggtheme.Rd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/man/ggtheme.Rd b/man/ggtheme.Rd index 57dd519355..df733e0370 100644 --- a/man/ggtheme.Rd +++ b/man/ggtheme.Rd @@ -111,7 +111,7 @@ theme_void( base_line_size = base_size/22, base_rect_size = base_size/22, ink = "black", - paper = "white" + paper = alpha(ink, 0) ) theme_test(