From b34407fb0f3bf7f1c4062db3fbf7ea4dede53874 Mon Sep 17 00:00:00 2001 From: aho Date: Wed, 15 Nov 2023 17:18:05 +0100 Subject: [PATCH] Avoid Inf values when defining var_limits for ColorBar() --- R/PlotEquiMap.R | 3 ++- R/PlotLayout.R | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/R/PlotEquiMap.R b/R/PlotEquiMap.R index 3b8f861..a2a7e3d 100644 --- a/R/PlotEquiMap.R +++ b/R/PlotEquiMap.R @@ -531,7 +531,8 @@ PlotEquiMap <- 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/PlotLayout.R b/R/PlotLayout.R index 6553f8a..c77b25a 100644 --- a/R/PlotLayout.R +++ b/R/PlotLayout.R @@ -348,7 +348,9 @@ PlotLayout <- 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