From 18b3623edc93bc0d4444edbf1e01497542f1cf45 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Thu, 29 May 2025 09:32:53 +0200 Subject: [PATCH 1/2] fix stretchy guide bug --- R/guides-.R | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/R/guides-.R b/R/guides-.R index 38a94252b0..4c208506c0 100644 --- a/R/guides-.R +++ b/R/guides-.R @@ -941,7 +941,11 @@ redistribute_null_units <- function(units, spacing, margin, type = "width") { # Get spacing between guides and margins in absolute units size <- switch(type, width = width_cm, height = height_cm) - spacing <- sum(rep(spacing, length.out = length(units) - 1)) + if (length(units) < 2) { + spacing <- unit(0, "cm") + } else { + spacing <- sum(rep(spacing, length.out = length(units) - 1)) + } margin <- switch(type, width = margin[c(2, 4)], height = margin[c(1, 3)]) margin <- sum(size(margin)) From cd56e926c334d577cd80eb1012ca517b88a1af93 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Thu, 29 May 2025 09:33:35 +0200 Subject: [PATCH 2/2] don't override legend key size --- R/guide-colorbar.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/guide-colorbar.R b/R/guide-colorbar.R index 2710860333..c38a5fc2d2 100644 --- a/R/guide-colorbar.R +++ b/R/guide-colorbar.R @@ -291,10 +291,10 @@ GuideColourbar <- ggproto( # We set the defaults in `theme` so that the `params$theme` can still # overrule defaults given here if (params$direction == "horizontal") { - theme$legend.key.width <- rel(5) + theme$legend.key.width <- (theme$legend.key.width %||% rel(1)) * 5 valid_position <- c("bottom", "top") } else { - theme$legend.key.height <- rel(5) + theme$legend.key.height <- (theme$legend.key.height %||% rel(1)) * 5 valid_position <- c("right", "left") }