plotSubannual: Plots sub-annual cycles

View source: R/plotSubannual.R

plotSubannualR Documentation

Plots sub-annual cycles

Description

For a list of Fields, plots the sub-annual cycles of the selected layers. Automatically splits data into separate panels based on Source, Quantity, Sire and/or Region, but instead these can be distinguished by aesthetics - see the col.by, linetype.by and alpha.by arguments. Summary or aggregate function can optionally be applied and plotted on top.

Usage

plotSubannual(
  fields,
  layers = NULL,
  gridcells = NULL,
  title = NULL,
  subtitle = NULL,
  cols = NULL,
  col.by = "Year",
  col.labels = waiver(),
  linetypes = NULL,
  linetype.by = NULL,
  linetype.labels = waiver(),
  alphas = NULL,
  alpha.by = NULL,
  alpha.labels = waiver(),
  linewidth = 0.5,
  size = 3,
  y.label = NULL,
  x.label = NULL,
  summary.function,
  summary.function.label = deparse(substitute(summary.function)),
  text.multiplier = NULL,
  plot = TRUE,
  ...
)

Arguments

fields

The data to plot. Can be a Field or a list of Fields.

layers

A list of strings specifying which layers to plot. Defaults to all layers.

gridcells

A list of gridcells to be plotted (either in different panels or the same panel). For formatting of this argument see selectGridcells. Leave empty or NULL to plot all gridsizrecells (but note that if this involves too many gridcells the code will stop)

title

A character string to override the default title.

subtitle

A character string to override the default subtitle.

cols, linetypes, alphas

A vector of colours, line types, or alpha values (respectively) to control the aesthetics of the lines. Only "cols" makes sense without a corresponding "xxx.by" argument (see above). The vectors can/should be named to match particular col/linetype/alpha values to particular Layers/Sources/Sites/Quantities/Regions.

col.by, linetype.by, alpha.by

Character strings defining the aspects of the data which which should be used to set the colour, line type and alpha (transparency). Can meaningfully take the values "Layer", "Source", "Site", "Region" or "Quantity". NOTE SPECIAL DEFAULT CASE: By default, col.by is set to "Year" which means that the years are plotted according to a colour gradient, and all other aspects of the the data are distinguished by different facet panels. To change this behaviour and colour the lines according to something different, set the "col.by" argument to one of the strings suggested above.

col.labels, linetype.labels, alpha.labels

A vector of character strings which are used as the labels for the lines. Must have the same length as the number of Sources/Layers/Sites/Quantities in the plot. The vectors can/should be named to match particular col/linewtype/alpha values to particular Layers/Sources/Sites/Quantities/Region.

linewidth

Numeric (as ggplot2), width of the lines on the plot, consistent with ggplot2. Note the width is doubled for the aggregate/summary line.

size

Numeric, size of the points for the aggregate/summary data, consistent with ggplot2.

x.label, y.label

Character strings (or expressions) for the x and y axes (optional)

summary.function

A function to summarise (aggregate) across year and plot on top. Obvious choice is mean, but there is flexibility to anything that operates on a vector of numerics - eg median, a 95th percentile, standard deviation.

summary.function.label

An optional character string to give a pretty label to the summary function legend.

text.multiplier

A number specifying an overall multiplier for the text on the plot. Make it bigger if the text is too small on large plots and vice-versa.

plot

Boolean, if FALSE return a data.table with the final data instead of the ggplot object. This can be useful for inspecting the structure of the facetting columns, amongst other things.

...

Arguments passed to ggplot2::facet_wrap(). See the ggplot2 documentation for full details but the following are particularly useful.

  • "nrow"The number of rows of facets

  • "ncol"The number of columns of facets

  • "scales"Whether the scales (ie. x and y ranges) should be fixed for all facets. Options are "fixed" (same scales on all facets, default) "free" (all facets can their x and y ranges), "free_x" and "free_y" (only x and y ranges can vary, respectively).

  • "labeller"A function to define the labels for the facets. This is a little tricky, please look to the ggplot2 documentation

Details

Note that like all DGVMTools plotting functions, plotSubannual splits the data into separate panels using the ggplot2::facet_wrap(). If you want to 'grid' the facets using ggplot2::facet_grid() you can do so afterwards. 'gridding the facets' implies the each column and row of facets vary by one specific aspect. For example you might have one column for each Source, and one row for each "Quantity".

Value

Returns either a ggplot2 object or a data.table (depending on the 'plot' argument)

Author(s)

Matthew Forrest matthew.forrest@senckenberg.de


MagicForrest/DGVMTools documentation built on Aug. 23, 2024, 8:05 a.m.