Learn R Programming

growthTrendR (version 0.2.1)

plot_mapping: Plot spatially interpolated tree-ring growth maps

Description

Visualizes spatial interpolation results produced by CFS_mapping and optionally exports raster files, static maps, and animations.

Usage

plot_mapping(
  mapping_results,
  crs.src = "EPSG:4326",
  parms.out = c("csv", "tif", "png", "gif"),
  dir.shp = NULL,
  dir.out = NULL,
  animation_fps = 1,
  ...
)

Value

A magick-image object representing an animated GIF composed of the generated frames.

Arguments

mapping_results

A list returned by CFS_mapping containing spatially interpolated rasters by species and year.

crs.src

Coordinate Reference System of the input data, specified as a string in the format 'EPSG:<ID>' (for example, 'EPSG:4326'). The function will stop with an error if `crs.src` is not provided in this format.

parms.out

Character vector indicating output formats to generate. Supported values are "csv", "tif", "png", and "gif".

dir.shp

Character or NULL. Path to the folder containing shapefiles for cropping data to the Canadian boreal regions. Only used for specific research purposes; if NULL (default), no cropping is applied and all data are included.

dir.out

Output directory used to save generated files. Required when parms.out is not empty.

animation_fps

Frames per second used when creating GIF animations.

...

Additional arguments passed to plot_tree_ring_map, such as png.text.

Details

This function assumes that spatial interpolation has already been performed using CFS_mapping. The input object is iterated by species and year to generate maps and optional exports.

When "gif" is requested in parms.out, yearly PNG images are combined into animated GIFs.

See Also

CFS_mapping

Examples

Run this code
# \donttest{
# Load processed demo data
dt.samples_trt <- readRDS(
  system.file("extdata", "dt.samples_trt.rds",
              package = "growthTrendR")
)
# prepare data for IDW model
cols.meta = c("uid_tree", "uid_site", "longitude", "latitude", "species")
dt.mapping <- dt.samples_trt$tr_all_wide[
  , c(..cols.meta, as.character(1991:1995)), with = FALSE]

# Run spatial interpolation
mapping_results <- CFS_mapping(
  dt.mapping,
  year.span = c(1991, 1993)
)

# generate png plots
img_ani <- plot_mapping(
mapping_results = mapping_results,
parms.out = NULL,
dir.shp = NULL,
dir.out = NULL,
png.text = list(
  text_top  = "Ring width measurement - ",
  text_bott = "Source: demo-samples",
  text_side = "ring width (mm)"
)
)
# }

Run the code above in your browser using DataLab