plot_variable: Plot results on a multi-panel figure of maps

View source: R/plot_variable.R

plot_variableR Documentation

Plot results on a multi-panel figure of maps

Description

plot_variable plots a map and fills in regions with colors to represent intensity in an areal-interpretion of model results

If maps are generating visual artefacts, please try using argument country to simplify the polygons used to represent land features.

In some sampling designs and/or analyses, it is not appropriate to extrapolate beyond samping stations. In these cases, the analyst may define the extrapolation-grid to only represent sampling stations, and then use format="points" to restrict mapping to bullets at those locations.

Usage

plot_variable(
  Y_gt,
  map_list = NULL,
  panel_labels = NULL,
  projargs = "+proj=longlat",
  map_resolution = "medium",
  file_name = "density",
  working_dir = getwd(),
  Format = "png",
  Res = 200,
  add = FALSE,
  outermargintext = c("Eastings", "Northings"),
  zlim = NULL,
  col = viridisLite::viridis,
  mar = c(0, 0, 2, 0),
  oma = c(4, 4, 0, 0),
  legend_x = c(0, 0.05),
  legend_y = c(0.05, 0.45),
  cex.legend = 1,
  mfrow = NULL,
  land_color = "grey",
  n_cells = NULL,
  xlim = NULL,
  ylim = NULL,
  country = NULL,
  contour_nlevels = 0,
  fun = mean,
  format = "sf",
  cex.points = 1,
  legend_digits = 1,
  ...
)

Arguments

Y_gt

matrix where values for every column are plotted as a map in a panel-figure with one panel per column

map_list

output from make_map_info, which is included in output of plot_results

panel_labels

vector defining titles to use for each panel; defaults to blank

projargs

Character passed to CRS and see that documentation for description. See https://proj.org/operations/projections/index.html for a list of projections to pass via projargs. As a stable default please consider projargs='+proj=natearth +lon_0=0 +units=km' where argument +lon_0 allows the user to center eastings on a specified longitude.

add

boolean indicating whether to add plot to an existing panel figure, or to define a new panel figure

outermargintext

vector defining text to plot in outer margins of panel figure

zlim

two numeric values, specifying range for defining bounds of color scale. If zlim=NULL, then a constant scale is inferred from the range of the plotted variable and a color-legend is plotted in the last panel. If zlim=NA then a different range is used in each panel from the range of Y_gt[,t] and a color-legend is plotted in every panel.

legend_x

two numeric values (generally between 0 and 1, but slightly lower/higher values generate colorbars that are just outside the plotting window) giving left and right-hand location of color legend

legend_y

two numeric values (see description for legend_x) giving bottom and top location of color legend

land_color

color for filling in land (use land_color=rgb(0,0,0,alpha=0) for transparent land)

n_cells

Integer used to determine the argument cell.size passed to rasterize when converting output at extrapolation-grid cells to a raster prior to plotting mapped outputs using plot_variable. An increased n_cells results in a decreased cell.size and hence higher resolution plots. The default value for n_cells will often need to be modified for a given purpose.

country

a character vector of country names.

contour_nlevels

number of levels used when adding contour lines, passed to contour as argument nlevels

fun

function or character. To determine what values to assign to cells that are covered by multiple spatial features. You can use functions such as min, max, or mean, or one of the following character values: 'first', 'last', 'count'. The default value is 'last'. In the case of SpatialLines*, 'length' is also allowed (currently for planar coordinate systems only).

If x represents points, fun must accept a na.rm argument, either explicitly or through the ellipses ('dots'). This means that fun=length fails, but fun=function(x,...)length(x) works, although it ignores the na.rm argument. To use the na.rm argument you can use a function like this: fun=function(x, na.rm){if (na.rm) length(na.omit(x)) else (length(x)}, or use a function that removes NA values in all cases, like this function to compute the number of unique values per grid cell "richness": fun=function(x, ...) {length(unique(na.omit(x)))} . If you want to count the number of points in each grid cell, you can use fun='count' or fun=function(x,...){length(x)}.

You can also pass multiple functions using a statement like fun=function(x, ...) c(length(x),mean(x)), in which case the returned object is a RasterBrick (multiple layers).

format

Character specifying whether to plot maps as a raster (the default), format="raster", or as points format="points"

cex.points

Numeric specifying the size of bullets when format="points"

legend_digits

number of digits (i.e., value passed to round) when creating labels for colorbar legend

...

arguments passed to par


James-Thorson/FishStatsUtils documentation built on Feb. 6, 2024, 4:26 a.m.