From 0aaab930ced1bafaa0803543cb6e411ea17947a0 Mon Sep 17 00:00:00 2001 From: Carlos Delgado Date: Fri, 28 Oct 2022 19:46:08 +0200 Subject: [PATCH 1/3] fixed cex_bar_titles (it was not used) --- R/PlotCombinedMap.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/PlotCombinedMap.R b/R/PlotCombinedMap.R index b6a52cb3..c5c974df 100644 --- a/R/PlotCombinedMap.R +++ b/R/PlotCombinedMap.R @@ -218,7 +218,7 @@ PlotCombinedMap <- function(maps, lon, lat, brks = brks, cols = cols, vertical = FALSE, subsampleg = NULL, bar_limits = display_range, var_limits = NULL, triangle_ends = NULL, plot = FALSE, draw_separators = TRUE, - bar_titles = bar_titles, title_scale = 1, label_scale = legend_scale * 1.5, + bar_titles = bar_titles, title_scale = cex_bar_titles, label_scale = legend_scale * 1.5, extra_margin = c(2, 0, 2, 0)) # Check legend_scale @@ -394,7 +394,7 @@ PlotCombinedMap <- function(maps, lon, lat, brks = colorbar$brks, cols = colorbar$cols, vertical = FALSE, subsampleg = NULL, bar_limits = display_range, var_limits = NULL, triangle_ends = NULL, plot = TRUE, draw_separators = TRUE, - bar_titles = bar_titles, title_scale = 1, label_scale = legend_scale * 1.5, + bar_titles = bar_titles, title_scale = cex_bar_titles, label_scale = legend_scale * 1.5, extra_margin = c(2, 0, 2, 0)) } -- GitLab From 2d8de27d12c53ec5d78884642f0bbab6d82fb2b4 Mon Sep 17 00:00:00 2001 From: Eva Rifa Date: Wed, 2 Nov 2022 11:06:04 +0100 Subject: [PATCH 2/3] Change example plot size and correct documentation format --- R/PlotCombinedMap.R | 97 ++++++++++++++++++++++++++++++++------------- 1 file changed, 69 insertions(+), 28 deletions(-) diff --git a/R/PlotCombinedMap.R b/R/PlotCombinedMap.R index c5c974df..7d639a49 100644 --- a/R/PlotCombinedMap.R +++ b/R/PlotCombinedMap.R @@ -1,37 +1,77 @@ #'Plot Multiple Lon-Lat Variables In a Single Map According to a Decision Function -#'@description Plot a number a two dimensional matrices with (longitude, latitude) dimensions on a single map with the cylindrical equidistant latitude and longitude projection. +#' +#'@description Plot a number a two dimensional matrices with (longitude, +#'latitude) dimensions on a single map with the cylindrical equidistant +#'latitude and longitude projection. +#' #'@author Nicolau Manubens, \email{nicolau.manubens@bsc.es} #'@author Veronica Torralba, \email{veronica.torralba@bsc.es} #' -#'@param maps List of matrices to plot, each with (longitude, latitude) dimensions, or 3-dimensional array with the dimensions (longitude, latitude, map). Dimension names are required. -#'@param lon Vector of longitudes. Must match the length of the corresponding dimension in 'maps'. -#'@param lat Vector of latitudes. Must match the length of the corresponding dimension in 'maps'. -#'@param map_select_fun Function that selects, for each grid point, which value to take among all the provided maps. This function receives as input a vector of values for a same grid point for all the provided maps, and must return a single selected value (not its index!) or NA. For example, the \code{min} and \code{max} functions are accepted. -#'@param display_range Range of values to be displayed for all the maps. This must be a numeric vector c(range min, range max). The values in the parameter 'maps' can go beyond the limits specified in this range. If the selected value for a given grid point (according to 'map_select_fun') falls outside the range, it will be coloured with 'col_unknown_map'. -#'@param map_dim Optional name for the dimension of 'maps' along which the multiple maps are arranged. Only applies when 'maps' is provided as a 3-dimensional array. Takes the value 'map' by default. -#'@param brks Colour levels to be sent to PlotEquiMap. This parameter is optional and adjusted automatically by the function. -#'@param cols List of vectors of colours to be sent to PlotEquiMap for the colour bar of each map. This parameter is optional and adjusted automatically by the function (up to 5 maps). The colours provided for each colour bar will be automatically interpolated to match the number of breaks. Each item in this list can be named, and the name will be used as title for the corresponding colour bar (equivalent to the parameter 'bar_titles'). -#'@param col_unknown_map Colour to use to paint the grid cells for which a map is not possible to be chosen according to 'map_select_fun' or for those values that go beyond 'display_range'. Takes the value 'white' by default. -#'@param mask Optional numeric array with dimensions (latitude, longitude), with values in the range [0, 1], indicating the opacity of the mask over each grid point. Cells with a 0 will result in no mask, whereas cells with a 1 will result in a totally opaque superimposed pixel coloured in 'col_mask'. -#'@param col_mask Colour to be used for the superimposed mask (if specified in 'mask'). Takes the value 'grey' by default. +#'@param maps List of matrices to plot, each with (longitude, latitude) +#' dimensions, or 3-dimensional array with the dimensions (longitude, latitude, +#' map). Dimension names are required. +#'@param lon Vector of longitudes. Must match the length of the corresponding +#' dimension in 'maps'. +#'@param lat Vector of latitudes. Must match the length of the corresponding +#' dimension in 'maps'. +#'@param map_select_fun Function that selects, for each grid point, which value +#' to take among all the provided maps. This function receives as input a +#' vector of values for a same grid point for all the provided maps, and must +#' return a single selected value (not its index!) or NA. For example, the +#' \code{min} and \code{max} functions are accepted. +#'@param display_range Range of values to be displayed for all the maps. This +#' must be a numeric vector c(range min, range max). The values in the +#' parameter 'maps' can go beyond the limits specified in this range. If the +#' selected value for a given grid point (according to 'map_select_fun') falls +#' outside the range, it will be coloured with 'col_unknown_map'. +#'@param map_dim Optional name for the dimension of 'maps' along which the +#' multiple maps are arranged. Only applies when 'maps' is provided as a +#' 3-dimensional array. Takes the value 'map' by default. +#'@param brks Colour levels to be sent to PlotEquiMap. This parameter is +#' optional and adjusted automatically by the function. +#'@param cols List of vectors of colours to be sent to PlotEquiMap for the +#' colour bar of each map. This parameter is optional and adjusted +#' automatically by the function (up to 5 maps). The colours provided for each +#' colour bar will be automatically interpolated to match the number of breaks. +#' Each item in this list can be named, and the name will be used as title for +#' the corresponding colour bar (equivalent to the parameter 'bar_titles'). +#'@param col_unknown_map Colour to use to paint the grid cells for which a map +#' is not possible to be chosen according to 'map_select_fun' or for those +#' values that go beyond 'display_range'. Takes the value 'white' by default. +#'@param mask Optional numeric array with dimensions (latitude, longitude), with +#' values in the range [0, 1], indicating the opacity of the mask over each +#' grid point. Cells with a 0 will result in no mask, whereas cells with a 1 +#' will result in a totally opaque superimposed pixel coloured in 'col_mask'. +#'@param col_mask Colour to be used for the superimposed mask (if specified in +#' 'mask'). Takes the value 'grey' by default. #'@param dots Array of same dimensions as 'var' or with dimensions #' c(n, dim(var)), where n is the number of dot/symbol layers to add to the #' plot. A value of TRUE at a grid cell will draw a dot/symbol on the #' corresponding square of the plot. By default all layers provided in 'dots' #' are plotted with dots, but a symbol can be specified for each of the #' layers via the parameter 'dot_symbol'. -#'@param bar_titles Optional vector of character strings providing the titles to be shown on top of each of the colour bars. -#'@param legend_scale Scale factor for the size of the colour bar labels. Takes 1 by default. -#'@param cex_bar_titles Scale factor for the sizes of the bar titles. Takes 1.5 by default. +#'@param bar_titles Optional vector of character strings providing the titles to +#' be shown on top of each of the colour bars. +#'@param legend_scale Scale factor for the size of the colour bar labels. Takes +#' 1 by default. +#'@param cex_bar_titles Scale factor for the sizes of the bar titles. Takes 1.5 +#' by default. #'@param plot_margin Numeric vector of length 4 for the margin sizes in the #' following order: bottom, left, top, and right. If not specified, use the #' default of par("mar"), c(5.1, 4.1, 4.1, 2.1). Used as 'margin_scale' in #' s2dv::PlotEquiMap. -#'@param fileout File where to save the plot. If not specified (default) a graphics device will pop up. Extensions allowed: eps/ps, jpeg, png, pdf, bmp and tiff -#'@param width File width, in the units specified in the parameter size_units (inches by default). Takes 8 by default. -#'@param height File height, in the units specified in the parameter size_units (inches by default). Takes 5 by default. -#'@param size_units Units of the size of the device (file or window) to plot in. Inches ('in') by default. See ?Devices and the creator function of the corresponding device. -#'@param res Resolution of the device (file or window) to plot in. See ?Devices and the creator function of the corresponding device. +#'@param fileout File where to save the plot. If not specified (default) a +#' graphics device will pop up. Extensions allowed: eps/ps, jpeg, png, pdf, bmp +#' and tiff +#'@param width File width, in the units specified in the parameter size_units +#' (inches by default). Takes 8 by default. +#'@param height File height, in the units specified in the parameter size_units +#' (inches by default). Takes 5 by default. +#'@param size_units Units of the size of the device (file or window) to plot in. +#' Inches ('in') by default. See ?Devices and the creator function of the +#' corresponding device. +#'@param res Resolution of the device (file or window) to plot in. See ?Devices +#' and the creator function of the corresponding device. #'@param drawleg Where to draw the common colour bar. Can take values TRUE, #' FALSE or:\cr #' 'up', 'u', 'U', 'top', 't', 'T', 'north', 'n', 'N'\cr @@ -39,13 +79,7 @@ #' 'right', 'r', 'R', 'east', 'e', 'E'\cr #' 'left', 'l', 'L', 'west', 'w', 'W' #'@param ... Additional parameters to be passed on to \code{PlotEquiMap}. - -#'@seealso \code{PlotCombinedMap} and \code{PlotEquiMap} #' -#'@importFrom s2dv PlotEquiMap ColorBar -#'@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 #'@examples #'# Simple example #'x <- array(1:(20 * 10), dim = c(lat = 10, lon = 20)) / 200 @@ -60,7 +94,7 @@ #' map_select_fun = max, #' display_range = c(0, 1), #' bar_titles = paste('% of belonging to', c('a', 'b', 'c')), -#' brks = 20, width = 10, height = 8) +#' brks = 20, width = 12, height = 10) #'} #' #'Lon <- c(0:40, 350:359) @@ -72,9 +106,16 @@ #'\dontrun{ #'PlotCombinedMap(data, lon = Lon, lat = Lat, map_select_fun = max, #' display_range = range(data), mask = mask, -#' width = 12, height = 8) +#' width = 14, height = 10) #'} #' +#'@seealso \code{PlotCombinedMap} and \code{PlotEquiMap} +#' +#'@importFrom s2dv PlotEquiMap ColorBar +#'@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 PlotCombinedMap <- function(maps, lon, lat, map_select_fun, display_range, -- GitLab From 69132b244d9abd396590d12e1d0b5873b6b0ca40 Mon Sep 17 00:00:00 2001 From: Eva Rifa Date: Wed, 2 Nov 2022 11:13:38 +0100 Subject: [PATCH 3/3] Update documentation --- man/PlotCombinedMap.Rd | 102 ++++++++++++++++++++++++++++------------- 1 file changed, 70 insertions(+), 32 deletions(-) diff --git a/man/PlotCombinedMap.Rd b/man/PlotCombinedMap.Rd index cf08c8f6..d013f80e 100644 --- a/man/PlotCombinedMap.Rd +++ b/man/PlotCombinedMap.Rd @@ -31,27 +31,53 @@ PlotCombinedMap( ) } \arguments{ -\item{maps}{List of matrices to plot, each with (longitude, latitude) dimensions, or 3-dimensional array with the dimensions (longitude, latitude, map). Dimension names are required.} - -\item{lon}{Vector of longitudes. Must match the length of the corresponding dimension in 'maps'.} - -\item{lat}{Vector of latitudes. Must match the length of the corresponding dimension in 'maps'.} - -\item{map_select_fun}{Function that selects, for each grid point, which value to take among all the provided maps. This function receives as input a vector of values for a same grid point for all the provided maps, and must return a single selected value (not its index!) or NA. For example, the \code{min} and \code{max} functions are accepted.} - -\item{display_range}{Range of values to be displayed for all the maps. This must be a numeric vector c(range min, range max). The values in the parameter 'maps' can go beyond the limits specified in this range. If the selected value for a given grid point (according to 'map_select_fun') falls outside the range, it will be coloured with 'col_unknown_map'.} - -\item{map_dim}{Optional name for the dimension of 'maps' along which the multiple maps are arranged. Only applies when 'maps' is provided as a 3-dimensional array. Takes the value 'map' by default.} - -\item{brks}{Colour levels to be sent to PlotEquiMap. This parameter is optional and adjusted automatically by the function.} - -\item{cols}{List of vectors of colours to be sent to PlotEquiMap for the colour bar of each map. This parameter is optional and adjusted automatically by the function (up to 5 maps). The colours provided for each colour bar will be automatically interpolated to match the number of breaks. Each item in this list can be named, and the name will be used as title for the corresponding colour bar (equivalent to the parameter 'bar_titles').} - -\item{col_unknown_map}{Colour to use to paint the grid cells for which a map is not possible to be chosen according to 'map_select_fun' or for those values that go beyond 'display_range'. Takes the value 'white' by default.} - -\item{mask}{Optional numeric array with dimensions (latitude, longitude), with values in the range [0, 1], indicating the opacity of the mask over each grid point. Cells with a 0 will result in no mask, whereas cells with a 1 will result in a totally opaque superimposed pixel coloured in 'col_mask'.} - -\item{col_mask}{Colour to be used for the superimposed mask (if specified in 'mask'). Takes the value 'grey' by default.} +\item{maps}{List of matrices to plot, each with (longitude, latitude) +dimensions, or 3-dimensional array with the dimensions (longitude, latitude, +map). Dimension names are required.} + +\item{lon}{Vector of longitudes. Must match the length of the corresponding +dimension in 'maps'.} + +\item{lat}{Vector of latitudes. Must match the length of the corresponding +dimension in 'maps'.} + +\item{map_select_fun}{Function that selects, for each grid point, which value +to take among all the provided maps. This function receives as input a +vector of values for a same grid point for all the provided maps, and must +return a single selected value (not its index!) or NA. For example, the +\code{min} and \code{max} functions are accepted.} + +\item{display_range}{Range of values to be displayed for all the maps. This +must be a numeric vector c(range min, range max). The values in the +parameter 'maps' can go beyond the limits specified in this range. If the +selected value for a given grid point (according to 'map_select_fun') falls +outside the range, it will be coloured with 'col_unknown_map'.} + +\item{map_dim}{Optional name for the dimension of 'maps' along which the +multiple maps are arranged. Only applies when 'maps' is provided as a +3-dimensional array. Takes the value 'map' by default.} + +\item{brks}{Colour levels to be sent to PlotEquiMap. This parameter is +optional and adjusted automatically by the function.} + +\item{cols}{List of vectors of colours to be sent to PlotEquiMap for the +colour bar of each map. This parameter is optional and adjusted +automatically by the function (up to 5 maps). The colours provided for each +colour bar will be automatically interpolated to match the number of breaks. +Each item in this list can be named, and the name will be used as title for +the corresponding colour bar (equivalent to the parameter 'bar_titles').} + +\item{col_unknown_map}{Colour to use to paint the grid cells for which a map +is not possible to be chosen according to 'map_select_fun' or for those +values that go beyond 'display_range'. Takes the value 'white' by default.} + +\item{mask}{Optional numeric array with dimensions (latitude, longitude), with +values in the range [0, 1], indicating the opacity of the mask over each +grid point. Cells with a 0 will result in no mask, whereas cells with a 1 +will result in a totally opaque superimposed pixel coloured in 'col_mask'.} + +\item{col_mask}{Colour to be used for the superimposed mask (if specified in +'mask'). Takes the value 'grey' by default.} \item{dots}{Array of same dimensions as 'var' or with dimensions c(n, dim(var)), where n is the number of dot/symbol layers to add to the @@ -60,26 +86,36 @@ corresponding square of the plot. By default all layers provided in 'dots' are plotted with dots, but a symbol can be specified for each of the layers via the parameter 'dot_symbol'.} -\item{bar_titles}{Optional vector of character strings providing the titles to be shown on top of each of the colour bars.} +\item{bar_titles}{Optional vector of character strings providing the titles to +be shown on top of each of the colour bars.} -\item{legend_scale}{Scale factor for the size of the colour bar labels. Takes 1 by default.} +\item{legend_scale}{Scale factor for the size of the colour bar labels. Takes +1 by default.} -\item{cex_bar_titles}{Scale factor for the sizes of the bar titles. Takes 1.5 by default.} +\item{cex_bar_titles}{Scale factor for the sizes of the bar titles. Takes 1.5 +by default.} \item{plot_margin}{Numeric vector of length 4 for the margin sizes in the following order: bottom, left, top, and right. If not specified, use the default of par("mar"), c(5.1, 4.1, 4.1, 2.1). Used as 'margin_scale' in s2dv::PlotEquiMap.} -\item{fileout}{File where to save the plot. If not specified (default) a graphics device will pop up. Extensions allowed: eps/ps, jpeg, png, pdf, bmp and tiff} +\item{fileout}{File where to save the plot. If not specified (default) a +graphics device will pop up. Extensions allowed: eps/ps, jpeg, png, pdf, bmp +and tiff} -\item{width}{File width, in the units specified in the parameter size_units (inches by default). Takes 8 by default.} +\item{width}{File width, in the units specified in the parameter size_units +(inches by default). Takes 8 by default.} -\item{height}{File height, in the units specified in the parameter size_units (inches by default). Takes 5 by default.} +\item{height}{File height, in the units specified in the parameter size_units +(inches by default). Takes 5 by default.} -\item{size_units}{Units of the size of the device (file or window) to plot in. Inches ('in') by default. See ?Devices and the creator function of the corresponding device.} +\item{size_units}{Units of the size of the device (file or window) to plot in. +Inches ('in') by default. See ?Devices and the creator function of the +corresponding device.} -\item{res}{Resolution of the device (file or window) to plot in. See ?Devices and the creator function of the corresponding device.} +\item{res}{Resolution of the device (file or window) to plot in. See ?Devices +and the creator function of the corresponding device.} \item{drawleg}{Where to draw the common colour bar. Can take values TRUE, FALSE or:\cr @@ -91,7 +127,9 @@ FALSE or:\cr \item{...}{Additional parameters to be passed on to \code{PlotEquiMap}.} } \description{ -Plot a number a two dimensional matrices with (longitude, latitude) dimensions on a single map with the cylindrical equidistant latitude and longitude projection. +Plot a number a two dimensional matrices with (longitude, +latitude) dimensions on a single map with the cylindrical equidistant +latitude and longitude projection. } \examples{ # Simple example @@ -107,7 +145,7 @@ PlotCombinedMap(list(a, b, c), lons, lats, map_select_fun = max, display_range = c(0, 1), bar_titles = paste('\% of belonging to', c('a', 'b', 'c')), - brks = 20, width = 10, height = 8) + brks = 20, width = 12, height = 10) } Lon <- c(0:40, 350:359) @@ -119,7 +157,7 @@ dim(mask) <- c(lat = 26, lon = 51) \dontrun{ PlotCombinedMap(data, lon = Lon, lat = Lat, map_select_fun = max, display_range = range(data), mask = mask, - width = 12, height = 8) + width = 14, height = 10) } } -- GitLab