From ac8e3eb60ec02c322f8d677c4cb87d84177602af Mon Sep 17 00:00:00 2001 From: Jared Knowles Date: Tue, 19 May 2026 16:47:36 -0600 Subject: [PATCH] fix: inherit plot background color in logo compositing The logo grob uses theme_void() (transparent background), so when arrangeGrob() composites it with a dark-themed plot, the logo strip falls back to the device default (white). Extract the plot's plot.background fill and apply it to the logo grob before compositing. Fixes the issue where theme_civilytics_dark(font_size = 16) piped to civilytics_logo(variant = "dark") would show a light background in the logo/caption area. --- R/logo.R | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/R/logo.R b/R/logo.R index a4ed5b5..70a090e 100644 --- a/R/logo.R +++ b/R/logo.R @@ -64,6 +64,16 @@ add_logo <- function(plot, logo, margin_param = NULL, font_scale = 1.1, position <- match.arg(position) at_top <- grepl("top", position) + # Inherit the plot's background color so the logo strip matches. + # make_logo_grob() uses theme_void() (transparent), so without this the + # logo area falls back to the device default (white). + bg_fill <- plot$theme$plot.background$fill + if (!is.null(bg_fill) && !is.na(bg_fill)) { + logo <- logo + ggplot2::theme( + plot.background = ggplot2::element_rect(fill = bg_fill, color = NA) + ) + } + # Inflate text sizes to compensate for arrangeGrob viewport shrinkage. # All theme text elements use rel() sizing, so scaling the root 'text' # element cascades to titles, axis labels, legends, captions, and strips. @@ -164,6 +174,14 @@ has_caption <- function(gg) { #' } add_logo_ga <- function(plot_list, logo, nrow = 1, widths = NULL, margin_param = NULL, font_scale = 1.1) { + # Inherit the background color from the first plot so the logo strip matches + bg_fill <- plot_list[[1]]$theme$plot.background$fill + if (!is.null(bg_fill) && !is.na(bg_fill)) { + logo <- logo + ggplot2::theme( + plot.background = ggplot2::element_rect(fill = bg_fill, color = NA) + ) + } + # Inflate text sizes to compensate for viewport shrinkage if (!is.null(font_scale) && font_scale != 1) { plot_list <- lapply(plot_list, function(p) {