diff --git a/NAMESPACE b/NAMESPACE index 94b5cc225c0c97514df8daf6e4fe7c04769c688e..a5dbed7bdec09f2186ac294fd965a48d432292cb 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -4,12 +4,6 @@ export(ClimColors) export(ClimPalette) export(ColorBarContinuous) export(ColorBarDiscrete) -export(PlotCombinedMap) -export(PlotForecastPDF) -export(PlotMostLikelyQuantileMap) -export(PlotPDFsOLE) -export(PlotTriangles4Categories) -export(PlotWeeklyClim) export(ShapeToMask) export(Viz2VarsVsLTime) export(VizACC) @@ -17,13 +11,19 @@ export(VizAnimateMap) export(VizAno) export(VizBoxWhisker) export(VizClim) +export(VizCombinedMap) export(VizEquiMap) +export(VizForecastPDF) export(VizLayout) export(VizMatrix) +export(VizMostLikelyQuantileMap) +export(VizPDFsOLE) export(VizRobinson) export(VizSection) export(VizStereoMap) +export(VizTriangles4Categories) export(VizVsLTime) +export(VizWeeklyClim) import(RColorBrewer) import(cowplot) import(easyNCDF) @@ -31,7 +31,6 @@ import(ggplot2) import(graphics) import(mapproj) import(maps) -import(multiApply) import(rnaturalearth) import(sf) import(stats) diff --git a/R/PlotCombinedMap.R b/R/VizCombinedMap.R similarity index 94% rename from R/PlotCombinedMap.R rename to R/VizCombinedMap.R index 53161852c631d6e0557adff75d486c6af7482f41..5119385ae254354fe9ed69134d5b901764ec8e60 100644 --- a/R/PlotCombinedMap.R +++ b/R/VizCombinedMap.R @@ -107,7 +107,7 @@ #'lons <- seq(0, 359.5, length = 20) #'lats <- seq(-89.5, 89.5, length = 10) #'\dontrun{ -#'PlotCombinedMap(list(a, b, c), lons, lats, +#'VizCombinedMap(list(a, b, c), lons, lats, #' toptitle = 'Maximum map', #' map_select_fun = max, #' display_range = c(0, 1), @@ -122,12 +122,12 @@ #'mask <- sample(c(0,1), replace = TRUE, size = 51 * 26) #'dim(mask) <- c(lat = 26, lon = 51) #'\dontrun{ -#'PlotCombinedMap(data, lon = Lon, lat = Lat, map_select_fun = max, +#'VizCombinedMap(data, lon = Lon, lat = Lat, map_select_fun = max, #' display_range = range(data), mask = mask, #' width = 14, height = 10) #'} #' -#'@seealso \code{PlotCombinedMap} and \code{VizEquiMap} +#'@seealso \code{VizCombinedMap} and \code{VizEquiMap} #' #'@import utils #'@importFrom maps map @@ -135,20 +135,20 @@ #'@importFrom grDevices adjustcolor bmp colorRampPalette dev.cur dev.new dev.off #' hcl jpeg pdf png postscript svg tiff #'@export -PlotCombinedMap <- function(maps, lon, lat, - map_select_fun, display_range, - map_dim = 'map', - brks = NULL, cols = NULL, - bar_limits = NULL, triangle_ends = c(FALSE, FALSE), - col_inf = NULL, col_sup = NULL, - col_unknown_map = 'white', - mask = NULL, col_mask = 'grey', - dots = NULL, - bar_titles = NULL, legend_scale = 1, - cex_bar_titles = 1.5, - 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, +VizCombinedMap <- function(maps, lon, lat, + map_select_fun, display_range, + map_dim = 'map', + brks = NULL, cols = NULL, + bar_limits = NULL, triangle_ends = c(FALSE, FALSE), + col_inf = NULL, col_sup = NULL, + col_unknown_map = 'white', + mask = NULL, col_mask = 'grey', + dots = NULL, + bar_titles = NULL, legend_scale = 1, + cex_bar_titles = 1.5, + 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(...) @@ -463,8 +463,8 @@ PlotCombinedMap <- function(maps, lon, lat, } VizEquiMap(var = ml_map, lon = lon, lat = lat, - brks = tbrks, cols = tcols, drawleg = FALSE, - filled.continents = FALSE, dots = dots, margin_scale = plot_margin, ...) + brks = tbrks, cols = tcols, drawleg = FALSE, + filled.continents = FALSE, dots = dots, margin_scale = plot_margin, ...) #---------------------- # Add overplot on top diff --git a/R/PlotForecastPDF.R b/R/VizForecastPDF.R similarity index 84% rename from R/PlotForecastPDF.R rename to R/VizForecastPDF.R index 77e26e43f2c8b5019f0de03174f6685a4a609fdf..4dffe78a56db7466ad43287a353df2f6d5a9892c 100644 --- a/R/PlotForecastPDF.R +++ b/R/VizForecastPDF.R @@ -46,23 +46,23 @@ #'@return A ggplot object containing the plot. #'@examples #'fcsts <- data.frame(fcst1 = rnorm(10), fcst2 = rnorm(10, 0.5, 1.2)) -#'PlotForecastPDF(fcsts,c(-1,1)) -#'@import ggplot2 stats +#'VizForecastPDF(fcsts,c(-1,1)) +#'@import ggplot2 #'@importFrom data.table data.table CJ setkey #'@importFrom reshape2 melt #'@importFrom plyr . dlply #'@importFrom s2dv InsertDim #'@export -PlotForecastPDF <- function(fcst, tercile.limits, extreme.limits = NULL, obs = NULL, - plotfile = NULL, title = "Set a title", var.name = "Varname (units)", - fcst.names = NULL, add.ensmemb = c("above", "below", "no"), - color.set = c("ggplot", "s2s4e", "hydro", "vitigeoss"), - memb_dim = 'member') { - value <- init <- extremes <- x <- ymin <- ymax <- tercile <- NULL +VizForecastPDF <- function(fcst, tercile.limits, extreme.limits = NULL, obs = NULL, + plotfile = NULL, title = "Set a title", var.name = "Varname (units)", + fcst.names = NULL, add.ensmemb = c("above", "below", "no"), + color.set = c("ggplot", "s2s4e", "hydro", "vitigeoss"), + memb_dim = 'member') { + value <- init <- extremes <- x <- ymin <- ymax <- tercile <- NULL y <- xend <- yend <- yjitter <- MLT <- lab.pos <- NULL ggColorHue <- function(n) { - hues <- seq(15, 375, length = n + 1) - hcl(h = hues, l = 65, c = 100)[1:n] + hues <- seq(15, 375, length = n + 1) + hcl(h = hues, l = 65, c = 100)[1:n] } #------------------------ # Define color sets @@ -301,8 +301,8 @@ PlotForecastPDF <- function(fcst, tercile.limits, extreme.limits = NULL, obs = N } else { plot <- plot + geom_segment(data = hatch.df[hatch.df$extremes != "Normal", ], - aes(x = x, y = y, - xend = xend, yend = yend, color = extremes)) + aes(x = x, y = y, + xend = xend, yend = yend, color = extremes)) } } #------------------------ @@ -311,8 +311,8 @@ PlotForecastPDF <- function(fcst, tercile.limits, extreme.limits = NULL, obs = N if (!is.null(obs)) { plot <- plot + geom_vline(data = obs.dt, - aes(xintercept = value), - linetype = "dashed", color = colorObs) + aes(xintercept = value), + linetype = "dashed", color = colorObs) } #------------------------ # Add ensemble members @@ -321,22 +321,22 @@ PlotForecastPDF <- function(fcst, tercile.limits, extreme.limits = NULL, obs = N plot <- plot + # this adds a grey box for ensmembers geom_rect(aes(xmin = -Inf, xmax = Inf, - ymin = -Inf, ymax = -pan.height / 10), - fill = "gray95", color = "black", width = 0.2) + + ymin = -Inf, ymax = -pan.height / 10), + fill = "gray95", color = "black", width = 0.2) + # this adds the ensemble members geom_point(data = jitter.df, - aes(x = x, - y = -pan.height / 10 - magic.ratio * yjitter, - shape = "Ensemble members"), - color = "black", fill = colorMember, alpha = 1) + aes(x = x, + y = -pan.height / 10 - magic.ratio * yjitter, + shape = "Ensemble members"), + color = "black", fill = colorMember, alpha = 1) } else if (add.ensmemb == "above") { plot <- plot + geom_point(data = jitter.df, - aes(x = x, - y = 0.7 * magic.ratio * yjitter, - shape = "Ensemble members"), - color = "black", fill = colorMember, alpha = 1) + aes(x = x, + y = 0.7 * magic.ratio * yjitter, + shape = "Ensemble members"), + color = "black", fill = colorMember, alpha = 1) } #------------------------ @@ -346,8 +346,8 @@ PlotForecastPDF <- function(fcst, tercile.limits, extreme.limits = NULL, obs = N plot <- plot + # this adds the obs diamond geom_point(data = obs.xy, - aes(x = x, y = ymax, size = "Observation"), - shape = 23, color = "black", fill = colorObs) + aes(x = x, y = ymax, size = "Observation"), + shape = 23, color = "black", fill = colorObs) } #------------------------ # Compute probability for each tercile and identify MLT @@ -357,9 +357,9 @@ PlotForecastPDF <- function(fcst, tercile.limits, extreme.limits = NULL, obs = N by = .(init, tercile)] # include potentially missing groups pct <- merge(pct, CJ(init = factor(levels(pct$init), levels = levels(pct$init)), - tercile = factor(c("Below normal", "Normal", "Above normal"), - levels = c("Above normal", "Normal", "Below normal"))), - by = c("init", "tercile"), all.y = T) + tercile = factor(c("Below normal", "Normal", "Above normal"), + levels = c("Above normal", "Normal", "Below normal"))), + by = c("init", "tercile"), all.y = T) pct[is.na(pct),"pct"] <- 0 tot <- pct[, .(tot = sum(pct)), by = init] pct <- merge(pct, tot, by = "init") @@ -375,9 +375,9 @@ PlotForecastPDF <- function(fcst, tercile.limits, extreme.limits = NULL, obs = N by = .(init, extremes)] # include potentially missing groups pct2 <- merge(pct2, CJ(init = factor(levels(pct2$init), levels = levels(pct2$init)), - extremes = factor(c("Below P10", "Normal", "Above P90"), - levels = c("Above P90", "Normal", "Below P10"))), - by = c("init", "extremes"), all.y=T) + extremes = factor(c("Below P10", "Normal", "Above P90"), + levels = c("Above P90", "Normal", "Below P10"))), + by = c("init", "extremes"), all.y=T) pct2[is.na(pct),"pct"] <- 0 tot2 <- pct2[, .(tot = sum(pct)), by = init] pct2 <- merge(pct2, tot2, by = "init") @@ -398,23 +398,23 @@ PlotForecastPDF <- function(fcst, tercile.limits, extreme.limits = NULL, obs = N } plot <- plot + geom_text(data = pct, - aes(x = lab.pos, y = labpos, label = paste0(pct, "%"), - hjust = as.integer(tercile) * -1.5 + 3.5), - vjust = vjust, angle = -90, size = 3.2) + + aes(x = lab.pos, y = labpos, label = paste0(pct, "%"), + hjust = as.integer(tercile) * -1.5 + 3.5), + vjust = vjust, angle = -90, size = 3.2) + geom_text(data = pct[MLT == T, ], - aes(x = lab.pos, y = labpos, label = "*", - hjust = as.integer(tercile) * -3.5 + 9), - vjust = 0.1, angle = -90, size = 7, color = "black") + aes(x = lab.pos, y = labpos, label = "*", + hjust = as.integer(tercile) * -3.5 + 9), + vjust = 0.1, angle = -90, size = 7, color = "black") #------------------------ # Add probability labels for extremes #------------------------ if (!is.null(extreme.limits)) { plot <- plot + geom_text(data = pct2[extremes != "Normal", ], - aes(x = lab.pos, y = 0.9 * y, label = paste0(pct, "%"), - hjust = as.integer(extremes) * -1.5 + 3.5), - vjust = -0.5, angle = -90, size = 3.2, - color = rep(colorLab, dim(fcst.df)[2])) + aes(x = lab.pos, y = 0.9 * y, label = paste0(pct, "%"), + hjust = as.integer(extremes) * -1.5 + 3.5), + vjust = -0.5, angle = -90, size = 3.2, + color = rep(colorLab, dim(fcst.df)[2])) } #------------------------ # Finish all theme and legend details @@ -422,29 +422,29 @@ PlotForecastPDF <- function(fcst, tercile.limits, extreme.limits = NULL, obs = N plot <- plot + theme_minimal() + scale_fill_manual(name = "Probability of\nterciles", - values = colorFill, drop = F) + + values = colorFill, drop = F) + scale_color_manual(name = "Probability of\nextremes", - values = colorHatch) + + values = colorHatch) + scale_shape_manual(name = "Ensemble\nmembers", - values = c(21)) + + values = c(21)) + scale_size_manual(name = "Observation", - values = c(3)) + + values = c(3)) + labs(x = var.name, - y = "Probability density\n(total area=1)", - title = title) + + y = "Probability density\n(total area=1)", + title = title) + theme(axis.text.x = element_blank(), - panel.grid.minor.x = element_blank(), - legend.key.size = unit(0.3, "in"), - panel.border = element_rect(fill = NA, color = "black"), - strip.background = element_rect(colour = "black", fill = "gray80"), - panel.spacing = unit(0.2, "in"), - panel.grid.major.x = element_line(color = "grey93"), - panel.background = element_rect(fill = "white"), - plot.background = element_rect(fill = "white", color = NA)) + + panel.grid.minor.x = element_blank(), + legend.key.size = unit(0.3, "in"), + panel.border = element_rect(fill = NA, color = "black"), + strip.background = element_rect(colour = "black", fill = "gray80"), + panel.spacing = unit(0.2, "in"), + panel.grid.major.x = element_line(color = "grey93"), + panel.background = element_rect(fill = "white"), + plot.background = element_rect(fill = "white", color = NA)) + guides(fill = guide_legend(order = 1), - color = guide_legend(order = 2), - shape = guide_legend(order = 3, label = F), - size = guide_legend(order = 4, label = F)) + color = guide_legend(order = 2), + shape = guide_legend(order = 3, label = F), + size = guide_legend(order = 4, label = F)) #------------------------ # Save to plotfile if needed, and return plot #------------------------ diff --git a/R/PlotMostLikelyQuantileMap.R b/R/VizMostLikelyQuantileMap.R similarity index 83% rename from R/PlotMostLikelyQuantileMap.R rename to R/VizMostLikelyQuantileMap.R index a43280591ff64749a0176b17652364d0e2124211..2de037c050619d9c427dece34be4f023ccb97fd2 100644 --- a/R/PlotMostLikelyQuantileMap.R +++ b/R/VizMostLikelyQuantileMap.R @@ -38,9 +38,9 @@ #' 'down', 'd', 'D', 'bottom', 'b', 'B', 'south', 's', 'S' (default)\cr #' 'right', 'r', 'R', 'east', 'e', 'E'\cr #' 'left', 'l', 'L', 'west', 'w', 'W' -#'@param ... Additional parameters to be sent to \code{PlotCombinedMap} and +#'@param ... Additional parameters to be sent to \code{VizCombinedMap} and #' \code{PlotEquiMap}. -#'@seealso \code{PlotCombinedMap} and \code{PlotEquiMap} +#'@seealso \code{VizCombinedMap} and \code{PlotEquiMap} #'@examples #'# Simple example #'x <- array(1:(20 * 10), dim = c(lat = 10, lon = 20)) / 200 @@ -50,10 +50,10 @@ #'lons <- seq(0, 359.5, length = 20) #'lats <- seq(-89.5, 89.5, length = 10) #'\dontrun{ -#'PlotMostLikelyQuantileMap(list(a, b, c), lons, lats, -#' toptitle = 'Most likely tercile map', -#' bar_titles = paste('% of belonging to', c('a', 'b', 'c')), -#' brks = 20, width = 10, height = 8) +#'VizMostLikelyQuantileMap(list(a, b, c), lons, lats, +#' toptitle = 'Most likely tercile map', +#' bar_titles = paste('% of belonging to', c('a', 'b', 'c')), +#' brks = 20, width = 10, height = 8) #'} #' #'# More complex example @@ -122,20 +122,20 @@ #' #'# 3. Plotting most likely quantile/bin #'\dontrun{ -#'PlotMostLikelyQuantileMap(bins, lons, lats, -#' toptitle = 'Most likely quantile map', -#' bar_titles = paste('% of belonging to', letters[1:n_bins]), -#' mask = 1 - (w1 + w2 / max(c(w1, w2))), -#' brks = 20, width = 10, height = 8) +#'VizMostLikelyQuantileMap(bins, lons, lats, +#' toptitle = 'Most likely quantile map', +#' bar_titles = paste('% of belonging to', letters[1:n_bins]), +#' mask = 1 - (w1 + w2 / max(c(w1, w2))), +#' brks = 20, width = 10, height = 8) #'} #'@importFrom maps map #'@importFrom graphics box image layout mtext par plot.new #'@importFrom grDevices adjustcolor bmp colorRampPalette dev.cur dev.new dev.off hcl jpeg pdf png postscript svg tiff #'@export -PlotMostLikelyQuantileMap <- function(probs, lon, lat, cat_dim = 'bin', - bar_titles = NULL, - col_unknown_cat = 'white', drawleg = T, - ...) { +VizMostLikelyQuantileMap <- function(probs, lon, lat, cat_dim = 'bin', + bar_titles = NULL, + col_unknown_cat = 'white', drawleg = T, + ...) { # Check probs error <- FALSE if (is.list(probs)) { @@ -210,13 +210,11 @@ PlotMostLikelyQuantileMap <- function(probs, lon, lat, cat_dim = 'bin', minimum_value <- ceiling(1 / nprobs * 10 * 1.1) * 10 - # By now, the PlotCombinedMap function is included below in this file. - # In the future, PlotCombinedMap will be part of s2dverification and will + # By now, the VizCombinedMap function is included below in this file. + # In the future, VizCombinedMap will be part of s2dverification and will # be properly imported. - PlotCombinedMap(probs * 100, lon, lat, map_select_fun = max, - display_range = c(minimum_value, 100), - map_dim = cat_dim, - bar_titles = bar_titles, - col_unknown_map = col_unknown_cat, - drawleg = drawleg, ...) + VizCombinedMap(probs * 100, lon, lat, map_select_fun = max, + display_range = c(minimum_value, 100), map_dim = cat_dim, + bar_titles = bar_titles, col_unknown_map = col_unknown_cat, + drawleg = drawleg, ...) } \ No newline at end of file diff --git a/R/PlotPDFsOLE.R b/R/VizPDFsOLE.R similarity index 95% rename from R/PlotPDFsOLE.R rename to R/VizPDFsOLE.R index a8b55bb871e92f4d1e06bc901d1a999134051d02..2232321d01654e38bf3938b6f55f68e36fe430ce 100644 --- a/R/PlotPDFsOLE.R +++ b/R/VizPDFsOLE.R @@ -29,7 +29,7 @@ #'@param dpi (optional) A numeric value indicating the plot resolution. #' (Default dpi = 300). #' -#'@return PlotPDFsOLE() returns a ggplot object containing the plot. +#'@return VizPDFsOLE() returns a ggplot object containing the plot. #' #'@examples #'# Example 1 @@ -40,12 +40,12 @@ #'attr(pdf_2, "name") <- "NAO2" #'dim(pdf_2) <- c(statistic = 2) #' -#'PlotPDFsOLE(pdf_1, pdf_2) +#'VizPDFsOLE(pdf_1, pdf_2) #'@import ggplot2 stats #'@export -PlotPDFsOLE <- function(pdf_1, pdf_2, nsigma = 3, legendPos = 'bottom', - legendSize = 1.0, plotfile = NULL, width = 30, - height = 15, units = "cm", dpi = 300) { +VizPDFsOLE <- function(pdf_1, pdf_2, nsigma = 3, legendPos = 'bottom', + legendSize = 1.0, plotfile = NULL, width = 30, + height = 15, units = "cm", dpi = 300) { y <- type <- NULL if(!is.null(plotfile)){ @@ -252,8 +252,8 @@ CombinedPDFs <- function(pdf_1, pdf_2) { return(data) } -dnorm_limit <- function(x,mean,sd){ - y <- dnorm(x,mean,sd) - y[x mean+sd] <- NA +dnorm_limit <- function(x, mean, sd){ + y <- dnorm(x, mean, sd) + y[x < mean | x > mean + sd] <- NA return(y) } diff --git a/R/PlotTriangles4Categories.R b/R/VizTriangles4Categories.R similarity index 90% rename from R/PlotTriangles4Categories.R rename to R/VizTriangles4Categories.R index 501536c72df82b181efe858c15fe0a1dcdc9d5d7..15a9dd7d334efd276f2be613d9bc666a0f67ee14 100644 --- a/R/PlotTriangles4Categories.R +++ b/R/VizTriangles4Categories.R @@ -66,28 +66,28 @@ #'names(dim(arr1)) <- c('dimx', 'dimy', 'dimcat') #'arr2 <- array(TRUE, dim = dim(arr1)) #'arr2[which(arr1 < 0.3)] <- FALSE -#'PlotTriangles4Categories(data = arr1, -#' cols = c('white','#fef0d9','#fdd49e','#fdbb84','#fc8d59'), -#' brks = c(-1, 0, 0.1, 0.2, 0.3, 0.4), -#' lab_legend = c('NAO+', 'BL','AR','NAO-'), -#' xtitle = "Target month", ytitle = "Lead time", -#' xlabels = c("Jan", "Feb", "Mar", "Apr")) +#'VizTriangles4Categories(data = arr1, +#' cols = c('white','#fef0d9','#fdd49e','#fdbb84','#fc8d59'), +#' brks = c(-1, 0, 0.1, 0.2, 0.3, 0.4), +#' lab_legend = c('NAO+', 'BL','AR','NAO-'), +#' xtitle = "Target month", ytitle = "Lead time", +#' xlabels = c("Jan", "Feb", "Mar", "Apr")) #'@importFrom grDevices dev.new dev.off dev.cur #'@importFrom graphics plot points polygon text title axis #'@importFrom RColorBrewer brewer.pal #'@importFrom ClimProjDiags Subset #'@export -PlotTriangles4Categories <- function(data, brks = NULL, cols = NULL, - toptitle = NULL, sig_data = NULL, - pch_sig = 18, col_sig = 'black', - cex_sig = 1, xlab = TRUE, ylab = TRUE, - xlabels = NULL, xtitle = NULL, - ylabels = NULL, ytitle = NULL, - legend = TRUE, lab_legend = NULL, - cex_leg = 1, col_leg = 'black', - cex_axis = 1.5, mar = c(5, 4, 0, 0), - fileout = NULL, size_units = 'px', - res = 100, figure.width = 1, ...) { +VizTriangles4Categories <- function(data, brks = NULL, cols = NULL, + toptitle = NULL, sig_data = NULL, + pch_sig = 18, col_sig = 'black', + cex_sig = 1, xlab = TRUE, ylab = TRUE, + xlabels = NULL, xtitle = NULL, + ylabels = NULL, ytitle = NULL, + legend = TRUE, lab_legend = NULL, + cex_leg = 1, col_leg = 'black', + cex_axis = 1.5, mar = c(5, 4, 0, 0), + fileout = NULL, size_units = 'px', + res = 100, figure.width = 1, ...) { # Checking the dimensions if (length(dim(data)) != 3) { stop("Parameter 'data' must be an array with three dimensions.") diff --git a/R/PlotWeeklyClim.R b/R/VizWeeklyClim.R similarity index 91% rename from R/PlotWeeklyClim.R rename to R/VizWeeklyClim.R index 5ca8e38dc4b1d8c9bd6fcfcf46c82779f4a01d93..3fbe62b67fb1b3bd53c6628a523d40d1d5659e0e 100644 --- a/R/PlotWeeklyClim.R +++ b/R/VizWeeklyClim.R @@ -63,26 +63,26 @@ #' #'@examples #'data <- array(rnorm(49*20*3, 274), dim = c(time = 49, sdate = 20, member = 3)) -#'PlotWeeklyClim(data = data, first_date = '2002-08-09', -#' last_date = '2002-09-15', ref_period = 2010:2019, -#' data_years = 2000:2019, time_dim = 'time', sdate_dim = 'sdate', -#' title = "Observed weekly means and climatology", -#' subtitle = "Target years: 2010 to 2019", -#' ytitle = paste0('tas', " (", "deg.C", ")")) +#'VizWeeklyClim(data = data, first_date = '2002-08-09', +#' last_date = '2002-09-15', ref_period = 2010:2019, +#' data_years = 2000:2019, time_dim = 'time', sdate_dim = 'sdate', +#' title = "Observed weekly means and climatology", +#' subtitle = "Target years: 2010 to 2019", +#' ytitle = paste0('tas', " (", "deg.C", ")")) #' -#'@import multiApply ggplot2 RColorBrewer stats +#'@import ggplot2 RColorBrewer stats #'@importFrom scales date_format #'@importFrom ClimProjDiags Subset #'@importFrom s2dv MeanDims #'@importFrom CSTools SplitDim #'@export -PlotWeeklyClim <- function(data, first_date, ref_period, last_date = NULL, - data_years = NULL, time_dim = 'time', - sdate_dim = 'sdate', ylim = NULL, - title = NULL, subtitle = NULL, - ytitle = NULL, legend = TRUE, - palette = "Blues", fileout = NULL, device = NULL, - width = 8, height = 6, units = 'in', dpi = 300) { +VizWeeklyClim <- function(data, first_date, ref_period, last_date = NULL, + data_years = NULL, time_dim = 'time', + sdate_dim = 'sdate', ylim = NULL, + title = NULL, subtitle = NULL, + ytitle = NULL, legend = TRUE, + palette = "Blues", fileout = NULL, device = NULL, + width = 8, height = 6, units = 'in', dpi = 300) { ## Check input arguments # data if (is.array(data)) { @@ -274,22 +274,22 @@ PlotWeeklyClim <- function(data, first_date, ref_period, last_date = NULL, alpha = 0.7, show.legend = legend) + # terciles clim geom_line(aes(y = clim, group = week, color = "climatological mean", linetype = "climatological mean"), - alpha = 1.0, size = 0.7, show.legend = legend) + # mean clim + alpha = 1.0, linewidth = 0.7, show.legend = legend) + # mean clim geom_line(aes(y = data, color = "observed daily mean", linetype = "observed daily mean"), - alpha = 1, size = 0.2, show.legend = legend) + # daily evolution + alpha = 1, linewidth = 0.2, show.legend = legend) + # daily evolution geom_line(aes(y = week_mean, group = week, color = "observed weekly mean", linetype = "observed weekly mean"), - alpha = 1, size = 0.7, show.legend = legend) + # weekly evolution + alpha = 1, linewidth = 0.7, show.legend = legend) + # weekly evolution theme_bw() + ylab(ytitle) + xlab(NULL) + ggtitle(title, subtitle = subtitle) + scale_x_date(breaks = seq(min(all$day), max(all$day), by = "7 days"), minor_breaks = NULL, expand = c(0.03, 0.03), labels = scales::date_format("%d %b %Y")) + theme(axis.text.x = element_text(angle = 45, hjust = 1), - panel.grid.major = element_line(size = 0.5, linetype = 'solid', + panel.grid.major = element_line(linewidth = 0.5, linetype = 'solid', colour = "gray92"), - panel.grid.minor = element_line(size = 0.25, linetype = 'solid', + panel.grid.minor = element_line(linewidth = 0.25, linetype = 'solid', colour = "gray92"), legend.spacing = unit(-0.2, "cm")) + scale_fill_manual(name = NULL, diff --git a/man/PlotCombinedMap.Rd b/man/VizCombinedMap.Rd similarity index 96% rename from man/PlotCombinedMap.Rd rename to man/VizCombinedMap.Rd index 64614004bf6cff2a2f6c1ca8937c2f5a61f00ae5..fc5926706290a7f2beee751fb72e1acc33d74d67 100644 --- a/man/PlotCombinedMap.Rd +++ b/man/VizCombinedMap.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/PlotCombinedMap.R -\name{PlotCombinedMap} -\alias{PlotCombinedMap} +% Please edit documentation in R/VizCombinedMap.R +\name{VizCombinedMap} +\alias{VizCombinedMap} \title{Plot Multiple Lon-Lat Variables In a Single Map According to a Decision Function} \usage{ -PlotCombinedMap( +VizCombinedMap( maps, lon, lat, @@ -170,7 +170,7 @@ c <- 1 - (a + b) lons <- seq(0, 359.5, length = 20) lats <- seq(-89.5, 89.5, length = 10) \dontrun{ -PlotCombinedMap(list(a, b, c), lons, lats, +VizCombinedMap(list(a, b, c), lons, lats, toptitle = 'Maximum map', map_select_fun = max, display_range = c(0, 1), @@ -185,14 +185,14 @@ 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) \dontrun{ -PlotCombinedMap(data, lon = Lon, lat = Lat, map_select_fun = max, +VizCombinedMap(data, lon = Lon, lat = Lat, map_select_fun = max, display_range = range(data), mask = mask, width = 14, height = 10) } } \seealso{ -\code{PlotCombinedMap} and \code{VizEquiMap} +\code{VizCombinedMap} and \code{VizEquiMap} } \author{ Nicolau Manubens, \email{nicolau.manubens@bsc.es} diff --git a/man/PlotForecastPDF.Rd b/man/VizForecastPDF.Rd similarity index 95% rename from man/PlotForecastPDF.Rd rename to man/VizForecastPDF.Rd index 31e3001fce60c33ce81730189eec426c55f5c5ce..cec38a5e279ce20eca081ce74d7da5ecfb850640 100644 --- a/man/PlotForecastPDF.Rd +++ b/man/VizForecastPDF.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/PlotForecastPDF.R -\name{PlotForecastPDF} -\alias{PlotForecastPDF} +% Please edit documentation in R/VizForecastPDF.R +\name{VizForecastPDF} +\alias{VizForecastPDF} \title{Plot one or multiple ensemble forecast pdfs for the same event} \usage{ -PlotForecastPDF( +VizForecastPDF( fcst, tercile.limits, extreme.limits = NULL, @@ -77,7 +77,7 @@ jittered points. The observed value is optionally shown as a diamond. } \examples{ fcsts <- data.frame(fcst1 = rnorm(10), fcst2 = rnorm(10, 0.5, 1.2)) -PlotForecastPDF(fcsts,c(-1,1)) +VizForecastPDF(fcsts,c(-1,1)) } \author{ Llorenç Lledó \email{llledo@bsc.es} diff --git a/man/PlotMostLikelyQuantileMap.Rd b/man/VizMostLikelyQuantileMap.Rd similarity index 84% rename from man/PlotMostLikelyQuantileMap.Rd rename to man/VizMostLikelyQuantileMap.Rd index 0dde63ff0480fd076769cc77b48a14ac9ec563d2..7b8ee9a253a6f9d84c1e943b3bd8a380e7d3a4fe 100644 --- a/man/PlotMostLikelyQuantileMap.Rd +++ b/man/VizMostLikelyQuantileMap.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/PlotMostLikelyQuantileMap.R -\name{PlotMostLikelyQuantileMap} -\alias{PlotMostLikelyQuantileMap} +% Please edit documentation in R/VizMostLikelyQuantileMap.R +\name{VizMostLikelyQuantileMap} +\alias{VizMostLikelyQuantileMap} \title{Plot Maps of Most Likely Quantiles} \usage{ -PlotMostLikelyQuantileMap( +VizMostLikelyQuantileMap( probs, lon, lat, @@ -48,7 +48,7 @@ FALSE or:\cr 'right', 'r', 'R', 'east', 'e', 'E'\cr 'left', 'l', 'L', 'west', 'w', 'W'} -\item{...}{Additional parameters to be sent to \code{PlotCombinedMap} and +\item{...}{Additional parameters to be sent to \code{VizCombinedMap} and \code{PlotEquiMap}.} } \description{ @@ -72,10 +72,10 @@ c <- 1 - (a + b) lons <- seq(0, 359.5, length = 20) lats <- seq(-89.5, 89.5, length = 10) \dontrun{ -PlotMostLikelyQuantileMap(list(a, b, c), lons, lats, - toptitle = 'Most likely tercile map', - bar_titles = paste('\% of belonging to', c('a', 'b', 'c')), - brks = 20, width = 10, height = 8) +VizMostLikelyQuantileMap(list(a, b, c), lons, lats, + toptitle = 'Most likely tercile map', + bar_titles = paste('\% of belonging to', c('a', 'b', 'c')), + brks = 20, width = 10, height = 8) } # More complex example @@ -144,15 +144,15 @@ bins <- multiApply::Apply(sample_data, 'time', binning, thresholds)$output1 # 3. Plotting most likely quantile/bin \dontrun{ -PlotMostLikelyQuantileMap(bins, lons, lats, - toptitle = 'Most likely quantile map', - bar_titles = paste('\% of belonging to', letters[1:n_bins]), - mask = 1 - (w1 + w2 / max(c(w1, w2))), - brks = 20, width = 10, height = 8) +VizMostLikelyQuantileMap(bins, lons, lats, + toptitle = 'Most likely quantile map', + bar_titles = paste('\% of belonging to', letters[1:n_bins]), + mask = 1 - (w1 + w2 / max(c(w1, w2))), + brks = 20, width = 10, height = 8) } } \seealso{ -\code{PlotCombinedMap} and \code{PlotEquiMap} +\code{VizCombinedMap} and \code{PlotEquiMap} } \author{ Veronica Torralba, \email{veronica.torralba@bsc.es}, Nicolau Manubens, diff --git a/man/PlotPDFsOLE.Rd b/man/VizPDFsOLE.Rd similarity index 91% rename from man/PlotPDFsOLE.Rd rename to man/VizPDFsOLE.Rd index e2c6606eb20822b0b29d40c99411dbb0de451710..165b5952232dcb9b778555f6b42da366a678d128 100644 --- a/man/PlotPDFsOLE.Rd +++ b/man/VizPDFsOLE.Rd @@ -1,11 +1,11 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/PlotPDFsOLE.R -\name{PlotPDFsOLE} -\alias{PlotPDFsOLE} +% Please edit documentation in R/VizPDFsOLE.R +\name{VizPDFsOLE} +\alias{VizPDFsOLE} \title{Plotting two probability density gaussian functions and the optimal linear estimation (OLE) as result of combining them.} \usage{ -PlotPDFsOLE( +VizPDFsOLE( pdf_1, pdf_2, nsigma = 3, @@ -52,7 +52,7 @@ unit. (Default units = 'cm').} (Default dpi = 300).} } \value{ -PlotPDFsOLE() returns a ggplot object containing the plot. +VizPDFsOLE() returns a ggplot object containing the plot. } \description{ This function plots two probability density gaussian functions @@ -67,7 +67,7 @@ pdf_2 <- c(1,0.5) attr(pdf_2, "name") <- "NAO2" dim(pdf_2) <- c(statistic = 2) -PlotPDFsOLE(pdf_1, pdf_2) +VizPDFsOLE(pdf_1, pdf_2) } \author{ Eroteida Sanchez-Garcia - AEMET, //email{esanchezg@aemet.es} diff --git a/man/PlotTriangles4Categories.Rd b/man/VizTriangles4Categories.Rd similarity index 89% rename from man/PlotTriangles4Categories.Rd rename to man/VizTriangles4Categories.Rd index 62a076ef4277a81af0540d4296fa451d18f4dfd8..b28c1a00f62ea8d7ce675830f7928871edee3ddb 100644 --- a/man/PlotTriangles4Categories.Rd +++ b/man/VizTriangles4Categories.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/PlotTriangles4Categories.R -\name{PlotTriangles4Categories} -\alias{PlotTriangles4Categories} +% Please edit documentation in R/VizTriangles4Categories.R +\name{VizTriangles4Categories} +\alias{VizTriangles4Categories} \title{Function to convert any 3-d numerical array to a grid of coloured triangles.} \usage{ -PlotTriangles4Categories( +VizTriangles4Categories( data, brks = NULL, cols = NULL, @@ -123,12 +123,12 @@ arr1 <- array(runif(n = 4 * 5 * 4, min = -1, max = 1), dim = c(4,5,4)) names(dim(arr1)) <- c('dimx', 'dimy', 'dimcat') arr2 <- array(TRUE, dim = dim(arr1)) arr2[which(arr1 < 0.3)] <- FALSE -PlotTriangles4Categories(data = arr1, - cols = c('white','#fef0d9','#fdd49e','#fdbb84','#fc8d59'), - brks = c(-1, 0, 0.1, 0.2, 0.3, 0.4), - lab_legend = c('NAO+', 'BL','AR','NAO-'), - xtitle = "Target month", ytitle = "Lead time", - xlabels = c("Jan", "Feb", "Mar", "Apr")) +VizTriangles4Categories(data = arr1, + cols = c('white','#fef0d9','#fdd49e','#fdbb84','#fc8d59'), + brks = c(-1, 0, 0.1, 0.2, 0.3, 0.4), + lab_legend = c('NAO+', 'BL','AR','NAO-'), + xtitle = "Target month", ytitle = "Lead time", + xlabels = c("Jan", "Feb", "Mar", "Apr")) } \author{ History:\cr diff --git a/man/PlotWeeklyClim.Rd b/man/VizWeeklyClim.Rd similarity index 89% rename from man/PlotWeeklyClim.Rd rename to man/VizWeeklyClim.Rd index 92276a618df6d138e151b5d7a68debc8c2b10c22..bba00054e30ab473f7e472445cb97e7c1a2d2ed1 100644 --- a/man/PlotWeeklyClim.Rd +++ b/man/VizWeeklyClim.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/PlotWeeklyClim.R -\name{PlotWeeklyClim} -\alias{PlotWeeklyClim} +% Please edit documentation in R/VizWeeklyClim.R +\name{VizWeeklyClim} +\alias{VizWeeklyClim} \title{Plots the observed weekly means and climatology of a timeseries data} \usage{ -PlotWeeklyClim( +VizWeeklyClim( data, first_date, ref_period, @@ -110,11 +110,11 @@ target period analyzed in the case study. } \examples{ data <- array(rnorm(49*20*3, 274), dim = c(time = 49, sdate = 20, member = 3)) -PlotWeeklyClim(data = data, first_date = '2002-08-09', - last_date = '2002-09-15', ref_period = 2010:2019, - data_years = 2000:2019, time_dim = 'time', sdate_dim = 'sdate', - title = "Observed weekly means and climatology", - subtitle = "Target years: 2010 to 2019", - ytitle = paste0('tas', " (", "deg.C", ")")) +VizWeeklyClim(data = data, first_date = '2002-08-09', + last_date = '2002-09-15', ref_period = 2010:2019, + data_years = 2000:2019, time_dim = 'time', sdate_dim = 'sdate', + title = "Observed weekly means and climatology", + subtitle = "Target years: 2010 to 2019", + ytitle = paste0('tas', " (", "deg.C", ")")) }