From 66937e9b7cac906d2d4e2f2aafd77031eeecf769 Mon Sep 17 00:00:00 2001 From: aho Date: Wed, 22 Nov 2023 16:37:45 +0100 Subject: [PATCH] Avoid Inf values when defining var_limits for color bar --- R/VizEquiMap.R | 3 ++- R/VizLayout.R | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/R/VizEquiMap.R b/R/VizEquiMap.R index 7449f7c..84e8ae0 100644 --- a/R/VizEquiMap.R +++ b/R/VizEquiMap.R @@ -514,7 +514,8 @@ VizEquiMap <- function(var, lon, lat, varu = NULL, varv = NULL, } if (!all(is.na(var))) { - var_limits <- c(min(var, na.rm = TRUE), max(var, na.rm = TRUE)) + var_limits <- c(min(var[!is.infinite(var)], na.rm = TRUE), + max(var[!is.infinite(var)], na.rm = TRUE)) } else { warning("All the data are NAs. The map will be filled with colNA.") if (!is.null(brks) && length(brks) > 1) { diff --git a/R/VizLayout.R b/R/VizLayout.R index 0e4e641..25e6bbd 100644 --- a/R/VizLayout.R +++ b/R/VizLayout.R @@ -332,7 +332,9 @@ VizLayout <- function(fun, plot_dims, var, ..., special_args = NULL, # Check the rest of parameters (unless the user simply wants to build an empty layout) if (!all(sapply(var, is_single_na))) { if (!all(is.na(unlist(var)))) { - var_limits <- c(min(unlist(var), na.rm = TRUE), max(unlist(var), na.rm = TRUE)) + tmp <- !is.infinite(unlist(var)) + var_limits <- c(min(unlist(var)[tmp], na.rm = TRUE), + max(unlist(var)[tmp], na.rm = TRUE)) } else { if (!is.null(brks)) { #NOTE: var_limits be like this to avoid warnings from ColorBar -- GitLab