From 40ffe8e51412979ba7d0ae6e611fd491271f2394 Mon Sep 17 00:00:00 2001 From: ARIADNA BATALLA FERRES Date: Thu, 15 May 2025 15:29:01 +0200 Subject: [PATCH 1/4] If mask is not NULL in VizCombinedMap; draw country borders after mask and not in VizEquiMap call --- R/VizCombinedMap.R | 24 +++++++++++++++++------- R/VizMostLikelyQuantileMap.R | 4 ++-- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/R/VizCombinedMap.R b/R/VizCombinedMap.R index 5119385..04c5d99 100644 --- a/R/VizCombinedMap.R +++ b/R/VizCombinedMap.R @@ -151,7 +151,9 @@ VizCombinedMap <- function(maps, lon, lat, size_units = 'in', res = 100, drawleg = T, return_leg = FALSE, ...) { args <- list(...) - + country.borders <- if (!is.null(args$country.borders)) args$country.borders else FALSE + args$country.borders <- NULL # Prevent duplication + # If there is any filenames to store the graphics, process them # to select the right device if (!is.null(fileout)) { @@ -461,10 +463,18 @@ VizCombinedMap <- function(maps, lon, lat, if (is.null(plot_margin)) { plot_margin <- c(5, 4, 4, 2) + 0.1 # default of par()$mar } - - VizEquiMap(var = ml_map, lon = lon, lat = lat, - brks = tbrks, cols = tcols, drawleg = FALSE, - filled.continents = FALSE, dots = dots, margin_scale = plot_margin, ...) + mask <- outer(1:length(lat), 1:length(lon), function(i, j) (i + j) %% 2) ## + dim(mask) <- c(length(lat), length(lon)) ## + names(dim(mask)) <- list(lat = NULL, lon = NULL) ## + + country.borders.VizEquiMap <- if (!is.null(mask)) FALSE else country.borders + + do.call(VizEquiMap, c(list( + var = ml_map, lon = lon, lat = lat, + brks = tbrks, cols = tcols, drawleg = FALSE, + filled.continents = FALSE, country.borders = country.borders.VizEquiMap, + dots = dots, margin_scale = plot_margin + ), args)) #---------------------- # Add overplot on top @@ -489,9 +499,9 @@ VizCombinedMap <- function(maps, lon, lat, coast_color <- 'black' } if (min(lon) < 0) { - map('world', interior = FALSE, add = TRUE, lwd = 1, col = coast_color) # Low resolution world map (lon -180 to 180). + map('world', interior = country.borders, add = TRUE, lwd = 1, col = 'red') ## coast_color) # Low resolution world map (lon -180 to 180). } else { - map('world2', interior = FALSE, add = TRUE, lwd = 1, col = coast_color) # Low resolution world map (lon 0 to 360). + map('world2', interior = country.borders, add = TRUE, lwd = 1, col = 'darkorange') ## coast_color) # Low resolution world map (lon 0 to 360). } box() } diff --git a/R/VizMostLikelyQuantileMap.R b/R/VizMostLikelyQuantileMap.R index 1796e39..a756b4e 100644 --- a/R/VizMostLikelyQuantileMap.R +++ b/R/VizMostLikelyQuantileMap.R @@ -39,8 +39,8 @@ #' 'right', 'r', 'R', 'east', 'e', 'E'\cr #' 'left', 'l', 'L', 'west', 'w', 'W' #'@param ... Additional parameters to be sent to \code{VizCombinedMap} and -#' \code{PlotEquiMap}. -#'@seealso \code{VizCombinedMap} and \code{PlotEquiMap} +#' \code{VizEquiMap}. +#'@seealso \code{VizCombinedMap} and \code{VizEquiMap} #'@examples #'# Simple example #'x <- array(1:(20 * 10), dim = c(lat = 10, lon = 20)) / 200 -- GitLab From bce6694cbb2d306670d32ec3c2403d40eaf357e8 Mon Sep 17 00:00:00 2001 From: ARIADNA BATALLA FERRES Date: Fri, 16 May 2025 11:27:26 +0200 Subject: [PATCH 2/4] Remove leftover testing code from R/VizCombinedMap.R --- R/VizCombinedMap.R | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/R/VizCombinedMap.R b/R/VizCombinedMap.R index 04c5d99..84fea57 100644 --- a/R/VizCombinedMap.R +++ b/R/VizCombinedMap.R @@ -463,9 +463,6 @@ VizCombinedMap <- function(maps, lon, lat, if (is.null(plot_margin)) { plot_margin <- c(5, 4, 4, 2) + 0.1 # default of par()$mar } - mask <- outer(1:length(lat), 1:length(lon), function(i, j) (i + j) %% 2) ## - dim(mask) <- c(length(lat), length(lon)) ## - names(dim(mask)) <- list(lat = NULL, lon = NULL) ## country.borders.VizEquiMap <- if (!is.null(mask)) FALSE else country.borders @@ -499,9 +496,9 @@ VizCombinedMap <- function(maps, lon, lat, coast_color <- 'black' } if (min(lon) < 0) { - map('world', interior = country.borders, add = TRUE, lwd = 1, col = 'red') ## coast_color) # Low resolution world map (lon -180 to 180). + map('world', interior = country.borders, add = TRUE, lwd = 1, col = coast_color) # Low resolution world map (lon -180 to 180). } else { - map('world2', interior = country.borders, add = TRUE, lwd = 1, col = 'darkorange') ## coast_color) # Low resolution world map (lon 0 to 360). + map('world2', interior = country.borders, add = TRUE, lwd = 1, col = coast_color) # Low resolution world map (lon 0 to 360). } box() } -- GitLab From 34eb6b1b2e1bbe2224e8e97e9e93e479cef728f0 Mon Sep 17 00:00:00 2001 From: ARIADNA BATALLA FERRES Date: Wed, 28 May 2025 14:43:54 +0200 Subject: [PATCH 3/4] Add shapefile after applying mask in VizCombinedMap.R --- R/VizCombinedMap.R | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/R/VizCombinedMap.R b/R/VizCombinedMap.R index 84fea57..7be8f16 100644 --- a/R/VizCombinedMap.R +++ b/R/VizCombinedMap.R @@ -149,7 +149,7 @@ VizCombinedMap <- function(maps, lon, lat, plot_margin = NULL, bar_extra_margin = c(2, 0, 2, 0), fileout = NULL, width = 8, height = 5, size_units = 'in', res = 100, drawleg = T, return_leg = FALSE, - ...) { + ...) { args <- list(...) country.borders <- if (!is.null(args$country.borders)) args$country.borders else FALSE args$country.borders <- NULL # Prevent duplication @@ -500,6 +500,14 @@ VizCombinedMap <- function(maps, lon, lat, } else { map('world2', interior = country.borders, add = TRUE, lwd = 1, col = coast_color) # Low resolution world map (lon 0 to 360). } + if (!is.null(args$shapefile)) { + shapefile_color <- if (!is.null(args$shapefile_color)) args$shapefile_color else "black" + shapefile_lwd <- if (!is.null(args$shapefile_lwd)) args$shapefile_lwd else 1 + filled.continents <- if (!is.null(args$filled.continents)) args$filled.continents else FALSE + maps::map(shapefile, interior = country.borders, #wrap = wrap_vec, + fill = filled.continents, add = TRUE, plot = TRUE, + lwd = shapefile_lwd, col = shapefile_color) + } box() } -- GitLab From ca78bd39c262441214c338ba01b1a36c53d53758 Mon Sep 17 00:00:00 2001 From: ARIADNA BATALLA FERRES Date: Wed, 28 May 2025 17:58:30 +0200 Subject: [PATCH 4/4] Fix processing of shapefile --- R/VizCombinedMap.R | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/R/VizCombinedMap.R b/R/VizCombinedMap.R index 7be8f16..2fdae19 100644 --- a/R/VizCombinedMap.R +++ b/R/VizCombinedMap.R @@ -501,10 +501,15 @@ VizCombinedMap <- function(maps, lon, lat, map('world2', interior = country.borders, add = TRUE, lwd = 1, col = coast_color) # Low resolution world map (lon 0 to 360). } if (!is.null(args$shapefile)) { + if (is.list(args$shapefile)) { + shape <- args$shapefile + } else { + shape <- readRDS(file = args$shapefile) + } shapefile_color <- if (!is.null(args$shapefile_color)) args$shapefile_color else "black" shapefile_lwd <- if (!is.null(args$shapefile_lwd)) args$shapefile_lwd else 1 filled.continents <- if (!is.null(args$filled.continents)) args$filled.continents else FALSE - maps::map(shapefile, interior = country.borders, #wrap = wrap_vec, + maps::map(shape, interior = country.borders, #wrap = wrap_vec, fill = filled.continents, add = TRUE, plot = TRUE, lwd = shapefile_lwd, col = shapefile_color) } -- GitLab