From 122c038e675b38db489a8895df996908141f316b Mon Sep 17 00:00:00 2001 From: rhijmans Date: Tue, 22 Oct 2024 01:45:53 -0700 Subject: [PATCH] m --- R/plot_legend.R | 12 +++++------- src/raster_methods.cpp | 3 +++ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/R/plot_legend.R b/R/plot_legend.R index 12facdb19..18069dc86 100644 --- a/R/plot_legend.R +++ b/R/plot_legend.R @@ -409,17 +409,15 @@ retro_labels <- function(x, lat=TRUE) { legtitle <- x$leg$title[1] } e <- x$leg$ext - if (length(legtitle) > 1) { + if (length(legtitle) > 1) { # or perhaps !inherits(legtitle, "expression") if (x$leg$x %in% c("top", "bottom")) { - txt <- paste(legtitle, collapse=" ") + legtitle <- paste(legtitle, collapse=" ") } else { - txt <- paste(legtitle, collapse="\n") + legtitle <- paste(legtitle, collapse="\n") } - } else { - txt <- legtitle - } + } # offset=.5*graphics::strheight("a",cex=x$leg$title.cex) - text(x=e$xmax, y=e$ymax, labels=txt, pos=3, cex=x$leg$title.cex, xpd=NA) + text(x=e$xmax, y=e$ymax, labels=legtitle, pos=3, cex=x$leg$title.cex, xpd=NA) } x } diff --git a/src/raster_methods.cpp b/src/raster_methods.cpp index b7f8113f5..a315db7a4 100644 --- a/src/raster_methods.cpp +++ b/src/raster_methods.cpp @@ -669,6 +669,9 @@ SpatRaster SpatRaster::weighted_mean(SpatRaster w, bool narm, SpatOptions &opt) w = w.mask(*this, false, NAN, NAN, topt); } SpatRaster wsum = w.summary("sum", narm, topt); + if (opt.names.empty()) { + opt.names = {"weighted.mean"}; + } return out.arith(wsum, "/", false, opt); }