plot_boot_vec: Plot stochastic vectors

View source: R/plot_boot_vec.R

plot_boot_vecR Documentation

Plot stochastic vectors

Description

Plot median values and confidence intervals (shaded region) for stochastic (e.g. bootstrapped) vectors.

Usage

plot_boot_vec(
  data,
  CIpct = 95,
  runsToKeep = NULL,
  ref_x = NULL,
  ref_y = NULL,
  col_lines = rgb(0, 0, 0, 1),
  add = FALSE,
  plot_shade = TRUE,
  plot_medCI = TRUE,
  plot_runs_which = "none",
  plot_runs_args = list(type = "l", lty = 1),
  plot_runs_col_fn = rainbow,
  plot_runs_labels = NULL,
  plot_runs_labels_args = list(pos = 4, cex = 1),
  plot_runs_endpt_args = list(),
  polygon_args = list(),
  plot_legend = FALSE,
  legend_args = list(),
  ...
)

Arguments

data

a numeric matrix or data frame that can be coerced to a numeric matrix where rows are runs and columns represent a numeric sequence (e.g. age, year). Note that the function would probably work for any numeric matrix, but it's intended for bootstrapped time- or age-series data.

CIpct

percentage to define the range of the confidence intervals to plot

runsToKeep

optional vector of integer values corresponding to the rows of data to include in the plot

ref_x, ref_y

x and y vectors for adding a reference line to the plot (e.g. base run values)

col_lines

color for lines depicting central tendency and confidence limits. Expects hex color

add

logical. Should a new plot be drawn (FALSE) or should it be added to an existing plot (TRUE)?

plot_runs_which

Specify individual runs to add to the plot: "none" add none of the individual runs, "all" adds all of the runs. Or specify a numeric vector of the runs you want to plot, corresponding to columns of data

plot_runs_args

list of arguments to pass to matpoints when adding runs to the plot

plot_runs_col_fn

name of the color function to use when adding runs to plot. It should be a function like rainbow or heat.colors where the first argument is n

plot_runs_labels

character vector of labels for runs to plot. Length should be equal to the number of individual runs being plotted

plot_runs_labels_args

arguments to pass to text when labeling runs.

plot_runs_endpt_args

arguments to pass to points for plotting the last non-NA value of a vector as a point (used in retrospective plots). When pch=NA (default), points will be plotted invisibly.

polygon_args

Optional arguments to pass to polygon for plotting shaded confidence bands.

plot_legend

logical. Should a legend be added to the plot? If TRUE, legend_args can be specified to format the legend.

legend_args

Optional arguments to pass to legend. By default, the legend just shows a message about the error bands.

...

other arguments to pass to matplot

Author(s)

Nikolai Klibansky

Examples

## Not run: 
bootData <- t(replicate(n=200,random_walk(x=1:200,mu=0.1)))
plot_boot_vec(bootData)
plot_boot_vec(bootData,plot_runs_which = sample(1:nrow(bootData),10))
plot_boot_vec(bootData,plot_runs_which = sample(1:nrow(bootData),10),plot_shade=FALSE)
plot_boot_vec(bootData,plot_runs_which = sample(1:nrow(bootData),10),plot_shade=FALSE,plot_medCI = FALSE)
ids <- sample(1:nrow(bootData),10)
plot_boot_vec(bootData,plot_runs_which = ids,plot_shade=FALSE,plot_medCI = FALSE,
plot_runs_labels=ids,plot_runs_labels_args = list(pos=4,cex=0.75))

## End(Not run)

nikolaifish/bamExtras documentation built on April 17, 2025, 9:44 p.m.