diff --git a/NEWS.md b/NEWS.md index bbb9a496bcf055dacdda8eb07968695bee6bd159..2a9cffb623360ea12ba8874d7bef2853324db8f6 100644 --- a/NEWS.md +++ b/NEWS.md @@ -13,6 +13,7 @@ + RainFARM checks 'slope' is not a vector + DESCRIPTION specifies the minimum multiApply version required + EnsClustering has a fixed 'closest_member' output + + PlotCombinedMap handles masks correctly ### CSTools 3.0.0 **Submission date to CRAN: 10-02-2020** diff --git a/R/PlotCombinedMap.R b/R/PlotCombinedMap.R index 96784eb88674539cc5b26150f3c1d35567066fff..7f8f5d64e0191ab40cd7e88b25d23fd95f9269e9 100644 --- a/R/PlotCombinedMap.R +++ b/R/PlotCombinedMap.R @@ -43,7 +43,17 @@ #' display_range = c(0, 1), #' bar_titles = paste('% of belonging to', c('a', 'b', 'c')), #' brks = 20, width = 10, height = 8) - +#' +#'Lon <- c(0:40, 350:359) +#'Lat <- 51:26 +#'data <- rnorm(51 * 26 * 3) +#'dim(data) <- c(map = 3, lon = 51, lat = 26) +#'mask <- sample(c(0,1), replace = TRUE, size = 51 * 26) +#'dim(mask) <- c(lat = 26, lon = 51) +#'PlotCombinedMap(data, lon = Lon, lat = Lat, map_select_fun = max, +#' display_range = range(data), mask = mask, +#' width = 12, height = 8) +#' #'@export PlotCombinedMap <- function(maps, lon, lat, map_select_fun, display_range, @@ -349,9 +359,19 @@ PlotCombinedMap <- function(maps, lon, lat, # Add overplot on top #---------------------- if (!is.null(mask)) { + dims_mask <- dim(mask) + latb <- sort(lat, index.return = TRUE) + dlon <- lon[2:dims_mask[2]] - lon[1:(dims_mask[2] - 1)] + wher <- which(dlon > (mean(dlon) + 1)) + if (length(wher) > 0) { + lon[(wher + 1):dims_mask[2]] <- lon[(wher + 1):dims_mask[2]] - 360 + } + lonb <- sort(lon, index.return = TRUE) + cols_mask <- sapply(seq(from = 0, to = 1, length.out = 10), function(x) adjustcolor(col_mask, alpha.f = x)) - image(lon, lat, t(mask), axes = FALSE, col = cols_mask, + image(lonb$x, latb$x, t(mask)[lonb$ix, latb$ix], + axes = FALSE, col = cols_mask, breaks = seq(from = 0, to = 1, by = 0.1), xlab='', ylab='', add = TRUE, xpd = TRUE) if (!exists('coast_color')) { diff --git a/man/PlotCombinedMap.Rd b/man/PlotCombinedMap.Rd index 616b84f98b6951040beb33961f285f571c4523ad..c45d1afb594c362a6ecf8e4e641cf7223f8a0e1c 100644 --- a/man/PlotCombinedMap.Rd +++ b/man/PlotCombinedMap.Rd @@ -82,6 +82,17 @@ PlotCombinedMap(list(a, b, c), lons, lats, display_range = c(0, 1), bar_titles = paste('\% of belonging to', c('a', 'b', 'c')), brks = 20, width = 10, height = 8) + +Lon <- c(0:40, 350:359) +Lat <- 51:26 +data <- rnorm(51 * 26 * 3) +dim(data) <- c(map = 3, lon = 51, lat = 26) +mask <- sample(c(0,1), replace = TRUE, size = 51 * 26) +dim(mask) <- c(lat = 26, lon = 51) +PlotCombinedMap(data, lon = Lon, lat = Lat, map_select_fun = max, + display_range = range(data), mask = mask, + width = 12, height = 8) + } \seealso{ \code{PlotCombinedMap} and \code{PlotEquiMap}