From 9f4e45c8f22ff96428bd1fcf92c3b71f9ee1e8dd Mon Sep 17 00:00:00 2001 From: edzer Date: Wed, 14 Feb 2024 22:05:20 +0100 Subject: [PATCH] robustify key.pos handling see https://github.com/r-spatial/stars/pull/664 --- R/plot.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/R/plot.R b/R/plot.R index 6daf760d1..5ee3bc47d 100644 --- a/R/plot.R +++ b/R/plot.R @@ -1,11 +1,11 @@ kw_dflt = function(x, key.pos) { - if (is.null(key.pos) || key.pos == 0) # no key: + if (is.null(key.pos) || key.pos[1] == 0) # no key: return(lcm(0)) font_scale = par("ps") / 12 - if (key.pos == -1) + if (key.pos[1] == -1) lcm(1.8 * font_scale) - else if (key.pos %in% c(2, 4) && (is.character(x[[1]]) || is.factor(x[[1]]))) { + else if (key.pos[1] %in% c(2, 4) && (is.character(x[[1]]) || is.factor(x[[1]]))) { strings = if (is.factor(x[[1]])) levels(x[[1]]) else @@ -111,7 +111,7 @@ plot.sf <- function(x, y, ..., main, pal = NULL, nbreaks = 10, breaks = "pretty" if (ncol(x) > 2 && !isTRUE(dots$add)) { # multiple maps to plot... cols = setdiff(names(x), attr(x, "sf_column")) lt = .get_layout(st_bbox(x), min(max.plot, length(cols)), par("din"), key.pos[1], key.width) - if (key.pos.missing || key.pos == -1) + if (key.pos.missing || key.pos[1] == -1) key.pos = lt$key.pos layout(lt$m, widths = lt$widths, heights = lt$heights, respect = compact)