Skip to content

Commit 16c5029

Browse files
authored
Fix legend key sizes (#6485)
* fix stretchy guide bug * don't override legend key size
1 parent 3085fc1 commit 16c5029

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

R/guide-colorbar.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,10 @@ GuideColourbar <- ggproto(
291291
# We set the defaults in `theme` so that the `params$theme` can still
292292
# overrule defaults given here
293293
if (params$direction == "horizontal") {
294-
theme$legend.key.width <- rel(5)
294+
theme$legend.key.width <- (theme$legend.key.width %||% rel(1)) * 5
295295
valid_position <- c("bottom", "top")
296296
} else {
297-
theme$legend.key.height <- rel(5)
297+
theme$legend.key.height <- (theme$legend.key.height %||% rel(1)) * 5
298298
valid_position <- c("right", "left")
299299
}
300300

R/guides-.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,11 @@ redistribute_null_units <- function(units, spacing, margin, type = "width") {
941941

942942
# Get spacing between guides and margins in absolute units
943943
size <- switch(type, width = width_cm, height = height_cm)
944-
spacing <- sum(rep(spacing, length.out = length(units) - 1))
944+
if (length(units) < 2) {
945+
spacing <- unit(0, "cm")
946+
} else {
947+
spacing <- sum(rep(spacing, length.out = length(units) - 1))
948+
}
945949
margin <- switch(type, width = margin[c(2, 4)], height = margin[c(1, 3)])
946950
margin <- sum(size(margin))
947951

0 commit comments

Comments
 (0)