plotTemporal: Plot temporal data

View source: R/plotTemporal.R

plotTemporalR Documentation

Plot temporal data

Description

Makes a line plot graphing the temporal evolution of data (using ggplot2). Allows control of panel layout and line aesthetics whilst simultaneously plotting multiple Sources, Layers, Gridcells (Sites) and Quantities.

Usage

plotTemporal(
  fields,
  layers = NULL,
  gridcells = NULL,
  title = character(0),
  subtitle = character(0),
  cols = NULL,
  col.by = "Layer",
  col.labels = waiver(),
  linetypes = NULL,
  linetype.by = NULL,
  linetype.labels = waiver(),
  linewidths = NULL,
  linewidth.by = NULL,
  linewidth.labels = waiver(),
  sizes = NULL,
  size.by = NULL,
  size.labels = waiver(),
  shapes = NULL,
  shape.by = NULL,
  shape.labels = waiver(),
  alphas = NULL,
  alpha.by = NULL,
  alpha.labels = waiver(),
  y.label = NULL,
  y.lim = NULL,
  x.label = NULL,
  x.lim = NULL,
  points = FALSE,
  legend.position = "bottom",
  text.multiplier = NULL,
  dropEmpty = FALSE,
  plotTrend = FALSE,
  plot = TRUE,
  ...
)

Arguments

fields

The data to be plotted, either as a Field or 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 gridcells (but note that if this involves too many gridcells the code will stop)

title

A character string to override the default title. Set to NULL for no title.

subtitle

A character string to override the default subtitle. Set to NULL for no subtitle.

cols, linetypes, linewidths, sizes, shapes, alphas

Values of colours, line types, line width, point sizes, point shapes or alpha values (respectively). These can either be a single values if the aesthetic has not specified by xxx.by argument above of a vector of values, or a vector of values which can/should be named to match particular col/size/linetype/shape/alpha values to particular Layers/Sources/Sites/Quantities.

col.by, linetype.by, linewidth.by, size.by, shape.by, alpha.by

Character strings defining the aspects of the data which which should be used to set the colour, line type, line width, point size and point shape and alpha (transparency). Can meaningfully take the values "Layer", "Source", "Site" or "Quantity". By default col.by is set to "Layer" and all others set to NULL, which means the different aspects are distinguished by different facet panels. Thus the standard behaviour is that different Layers are distinguished by different colours, but everything is separated into different panels.

col.labels, linetype.labels, linewidth.labels, size.labels, shape.labels, alpha.labels

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

x.label, y.label

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

x.lim, y.lim

Limits for the x and y axes (each a two-element numeric, optional)

points

Logical, if TRUE plot data as points (with geom_points) instead of lines (with geom_lines). Good for plotting time series with missing data where geom_lines joins lines over the gaps which is not helpful

legend.position

Position of the legend, in the ggplot2 style. Passed to the ggplot function theme(). Can be "none", "top", "bottom", "left" or "right" or two-element numeric vector

text.multiplier

A number specifying an overall multiplier for the text on the plot.

dropEmpty

Logical, if TRUE don't plot time series lines consisting only of zeros (default is FALSE).

plotTrend

Logical, if TRUE plot the linear trend (default is FALSE)

plot

Logical, if FALSE return the data.table of data instead of the plot

...

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

  • "nrow"The number of rows of facets. (facet_wrap)

  • "ncol"The number of columns of facets. (facet_wrap)

  • "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). (facet_wrap)

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

  • "se"Boolean to determine whether or not to show the confidence intervals for the trend line (stat_smooth)

Details

It allows fairly fine-grained control with respect to labelling lines corresponding to different Sources, Layers, Sites and Quantities with different colours, sizes, linetypes, alpha (transparency) values, and text labels. It also allows one to decide if you want different Sources/Layers/Quantities on the same panel or on different panels. The default is to put different Sources (ie. runs and datasets) and Quantities (ie different output variables) on different panels, and Layers on the same panel distinguished by colour.

Value

A ggplot

Author(s)

Matthew Forrest matthew.forrest@senckenberg.de


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