eems.population.grid: A function to plot the constructed population grid and...

View source: R/eems.population.grid.R

eems.population.gridR Documentation

A function to plot the constructed population grid and optionally the initial sampling locations

Description

Given an EEMS output directory, this function generates one figure to visualize the EEMS population grid. All edges are shown in the same color to visualize the grid before estimating migration and diversity rates. This can be helpful if EEMS exits with the error message "The population grid is not connected".

Usage

eems.population.grid(
  mcmcpath,
  plotpath,
  longlat,
  plot.width = 10,
  plot.height = 10,
  out.png = FALSE,
  res = 600,
  add.grid = TRUE,
  col.grid = "gray80",
  lwd.grid = 1,
  add.demes = FALSE,
  col.demes = "black",
  pch.demes = 19,
  min.cex.demes = 1,
  max.cex.demes = 3,
  add.outline = TRUE,
  col.outline = "gray90",
  lwd.outline = 2,
  add.coord = FALSE,
  col.coord = "red",
  pch.coord = 3,
  datapath = NULL
)

Arguments

mcmcpath

A vector of EEMS output directories, for the same dataset. Warning: There is minimal checking that the given directories are for the same dataset.

plotpath

The full path and the file name for the graphics to be generated.

longlat

A logical value indicating whether the coordinates are given as pairs (longitude, latitude) or (latitude, longitude).

plot.width

The width of the graphics region for the two rate contour plots, in inches. The default value is 10.

plot.height

The height of the graphics region, in inches. The default value is 10.

out.png

A logical value which, if set, forces output graphics to be generated as PNGs (if TRUE) or PDFs (if FALSE). Defaults to FALSE.

res

Resolution, in dots per inch; used only for PNG images. The default is 600.

add.grid

A logical value indicating whether to add the population grid or not.

col.grid

The color of the population grid. Defaults to gray80.

lwd.grid

The line width of the population grid. Defaults to 1.

add.demes

A logical value indicating whether to add the observed demes or not.

col.demes

The color of the demes. Defaults to black.

pch.demes

The symbol, specified as an integer, or the character to be used for plotting the demes. Defaults to 19.

min.cex.demes

The minimum size of the deme symbol/character.

max.cex.demes

The maximum size of the deme symbol/character. Defaults to 1 and 3, respectively. If max.cex.demes > min.cex.demes, then demes with more samples also have bigger size: the deme with the fewest samples has size min.cex.demes and the deme with the most samples has size max.cex.demes.

add.outline

A logical value indicating whether to add the habitat outline or not.

col.outline

The color of the habitat outline. Defaults to white.

lwd.outline

The line width of the habitat outline. Defaults to 2.

add.coord

A logical value indicating whether to add the original sampling locations to the plot or not.

col.coord

The color of the sampling locations. Defaults to red.

pch.coord

The symbol, specified as an integer, or the character to be used for plotting the sampling locations. Defaults to 3.

datapath

The full path and the file name of the input dataset (the three files datapath.coord, datapath.diffs, datapath.outer). Must be specified if add_coord = TRUE.

Value

Passes on the return value of dev.off() indicating the graphics device.

See Also

eems.plots, eems.voronoi.samples, eems.posterior.draws

Examples

# Use the provided example or supply the path to your own EEMS run.
extdata_path <- system.file("extdata", package = "reems")
eems_results <- file.path(extdata_path, "EEMS-example")
# Create a temporary output directory for this example 
outdir <- file.path(tempdir(), "path_out")
dir.create(outdir, showWarnings = FALSE)
name_figures <- file.path(outdir, "EEMS-grid_connected")

eems.population.grid(eems_results,
  name_figures,
  longlat = TRUE,
  add.outline = TRUE,
  col.outline = "purple",
  lwd.outline = 3,
  add.grid = TRUE,
  col.grid = "green",
  lwd.grid = 2,
  out.png = FALSE
)

# It is more interesting to see an example where the grid is unconnected
# due to the unusual shape of the habitat.
eems_results <- file.path(extdata_path, "EEMS-popgrid")

name_figures <- file.path(outdir, "EEMS-grid_not_connected")

eems.population.grid(
  mcmcpath = eems_results,
  plotpath = name_figures,
  longlat = FALSE,
  add.outline = TRUE, col.outline = "purple", lwd.outline = 3,
  add.grid = TRUE, col.grid = "green", lwd.grid = 2
)
# Delete the output file to tidy up.
unlink(outdir, recursive = TRUE, force = TRUE)

reems documentation built on May 6, 2026, 1:07 a.m.