From b4827316f11b96640f2321acc4ccfcf90168c380 Mon Sep 17 00:00:00 2001 From: aho Date: Fri, 29 Sep 2023 15:08:29 +0200 Subject: [PATCH] Bug fix in mlmap when upper triangle is not required --- R/PlotCombinedMap.R | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/R/PlotCombinedMap.R b/R/PlotCombinedMap.R index d7d5f49e..8e27f21f 100644 --- a/R/PlotCombinedMap.R +++ b/R/PlotCombinedMap.R @@ -359,11 +359,12 @@ PlotCombinedMap <- function(maps, lon, lat, } else { brks_norm <- vector('list', length = nmap) - range_width <- display_range[2] - display_range[1] #vector('list', length = nmap) + range_width <- vector('list', length = nmap) slightly_tune_val <- vector('list', length = nmap) for (ii in 1:nmap) { brks_norm[[ii]] <- seq(0, 1, length.out = length(colorbar$brks[[ii]])) slightly_tune_val[[ii]] <- brks_norm[[ii]][2] / (length(brks_norm[[ii]]) * 2) + range_width[[ii]] <- diff(range(colorbar$brks[[ii]])) } ml_map <- apply(maps, c(lat_dim, lon_dim), function(x) { if (any(is.na(x))) { @@ -371,15 +372,16 @@ PlotCombinedMap <- function(maps, lon, lat, } else { res <- which(x == map_select_fun(x)) if (length(res) > 0) { - res <- res[1] + res <- res_ind <- res[1] if (map_select_fun(x) < display_range[1] || map_select_fun(x) > display_range[2]) { res <- -0.5 } else { - res <- res + (map_select_fun(x) - display_range[1]) / range_width - if (map_select_fun(x) == display_range[1]) { - res <- res + slightly_tune_val - } + res <- res + ((map_select_fun(x) - colorbar$brks[[res_ind]][1]) / + range_width[[res_ind]]) + if (map_select_fun(x) == colorbar$brks[[res_ind]][1]) { + res <- res + slightly_tune_val[[res_ind]] + } } } else { res <- -0.5 -- GitLab