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) {