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") } 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))