Skip to contents

Creates a line plot of all tree-ring series in an rwl dataframe, with optional z-score standardization and faceting options.

Usage

trs_plot_rwl(
  x,
  zscore = TRUE,
  facet = FALSE,
  ncol = 1,
  color = NULL,
  scale_y = "fixed"
)

Arguments

x

A data.frame (typically of class 'rwl') with multiple columns of ring-width values. Row names must be numeric and represent calendar years.

zscore

Logical. If TRUE, the ring-width series are standardized to z-scores before plotting. Defaults to TRUE.

facet

Logical. If TRUE, creates a faceted plot with each series in a separate panel. If FALSE, plots all series overlaid on the same plot. Defaults to FALSE.

ncol

Numeric. Number of columns for faceted plots (only used when facet = TRUE). Defaults to 1.

color

Character string or vector specifying line color(s). When NULL and facet = FALSE, each series gets a different color. When a single color is specified, all lines use that color. When a vector of colors is provided, each series gets the corresponding color. Defaults to NULL.

scale_y

Character string specifying y-axis scaling for faceted plots. Options are "fixed", "free", "free_x", or "free_y". Defaults to "fixed".

Value

A ggplot object showing the plotted time series.

Details

The function assumes that the rwl dataframe is already calendar-dated with years as row names. When facet = FALSE, all series are plotted on the same axes with different colors. When facet = TRUE, each series gets its own panel for easier individual inspection. When providing a vector of colors, the length must match the number of series in the data. Required helper functions include: trs_trim and trs_zscore.

Required packages: ggplot2, plyr, tidyr, dplyr

Examples

rwl_data <- trs_pseudo_rwl(n_series = 5, series_length = c(75, 100), end_date = c(2000, 2025))

# Overlaid plot with z-scores
trs_plot_rwl(rwl_data, zscore = TRUE, facet = FALSE)
#> Error in `[[<-.data.frame`(`*tmp*`, col, value = c(-0.843066339524642, 0.38854361734614, 1.1802928753345, 0.38854361734614, 0.212599337793171, 1.1802928753345, 1.09232073555802, 1.00434859578153, 2.41190283220528, 3.11567995041716, 2.67581925153473, 0.916376456005046, 0.564487896899109, 0.828404316228562, 0.124627198016687, 1.26826501511098, 1.1802928753345, 1.44420929466395, 0.124627198016687, 0.212599337793171, -0.315233500865735, -0.931038479301126, 0.124627198016687, 0.564487896899109, -0.139289221312767, 0.124627198016687, -0.667122059971673, 0.38854361734614, -0.315233500865735, -0.227261361089251, -0.667122059971673, -0.579149920195189, -1.28292703840706, -2.42656485550136, -2.16264843617191, -0.843066339524642, -0.755094199748157, -1.1069827588541, -1.01901061907761, -1.634815597513, -0.843066339524642, -1.54684345773652, -0.227261361089251, -0.491177780418704, 1.26826501511098, 0.212599337793171, -0.315233500865735, -1.1069827588541, -0.667122059971673, -1.1069827588541, -0.40320564064222, -0.667122059971673, -0.667122059971673, -0.0513170815362822, -0.667122059971673, 0.124627198016687, 0.124627198016687, 0.124627198016687, -0.40320564064222, 0.300571477569655, -0.0513170815362822, -0.0513170815362822, -0.755094199748157, -1.89873201684245, -1.54684345773652, -1.19495489863058, -0.931038479301126, -0.931038479301126, -0.315233500865735, 0.652460036675593, 0.38854361734614, 1.35623715488747, 0.476515757122624, 1.1802928753345, 1.70812571399341, 0.828404316228562, 0.828404316228562, 1.09232073555802, 1.44420929466395, 1.1802928753345, 0.38854361734614, 0.564487896899109, 0.740432176452077, -0.579149920195189, -0.0513170815362822, 0.564487896899109, 0.476515757122624, -0.315233500865735, -0.843066339524642, -0.931038479301126, -0.491177780418704, -0.755094199748157, -0.491177780418704, -0.755094199748157, 0.212599337793171, 0.212599337793171)): replacement has 96 rows, data has 103

# Faceted plot with raw values
trs_plot_rwl(rwl_data, zscore = FALSE, facet = TRUE, ncol = 1)
#> Ignoring unknown labels:
#> • colour : ""


# Custom colors for each series
col_vec <- c("#0fa3b1", "#07beb8", "#3dccc7", "#68d8d6", "#9ceaef")
trs_plot_rwl(rwl_data, color = c("tomato3", "navyblue", "forestgreen", "purple", "orange"))
#> Error in `[[<-.data.frame`(`*tmp*`, col, value = c(-0.843066339524642, 0.38854361734614, 1.1802928753345, 0.38854361734614, 0.212599337793171, 1.1802928753345, 1.09232073555802, 1.00434859578153, 2.41190283220528, 3.11567995041716, 2.67581925153473, 0.916376456005046, 0.564487896899109, 0.828404316228562, 0.124627198016687, 1.26826501511098, 1.1802928753345, 1.44420929466395, 0.124627198016687, 0.212599337793171, -0.315233500865735, -0.931038479301126, 0.124627198016687, 0.564487896899109, -0.139289221312767, 0.124627198016687, -0.667122059971673, 0.38854361734614, -0.315233500865735, -0.227261361089251, -0.667122059971673, -0.579149920195189, -1.28292703840706, -2.42656485550136, -2.16264843617191, -0.843066339524642, -0.755094199748157, -1.1069827588541, -1.01901061907761, -1.634815597513, -0.843066339524642, -1.54684345773652, -0.227261361089251, -0.491177780418704, 1.26826501511098, 0.212599337793171, -0.315233500865735, -1.1069827588541, -0.667122059971673, -1.1069827588541, -0.40320564064222, -0.667122059971673, -0.667122059971673, -0.0513170815362822, -0.667122059971673, 0.124627198016687, 0.124627198016687, 0.124627198016687, -0.40320564064222, 0.300571477569655, -0.0513170815362822, -0.0513170815362822, -0.755094199748157, -1.89873201684245, -1.54684345773652, -1.19495489863058, -0.931038479301126, -0.931038479301126, -0.315233500865735, 0.652460036675593, 0.38854361734614, 1.35623715488747, 0.476515757122624, 1.1802928753345, 1.70812571399341, 0.828404316228562, 0.828404316228562, 1.09232073555802, 1.44420929466395, 1.1802928753345, 0.38854361734614, 0.564487896899109, 0.740432176452077, -0.579149920195189, -0.0513170815362822, 0.564487896899109, 0.476515757122624, -0.315233500865735, -0.843066339524642, -0.931038479301126, -0.491177780418704, -0.755094199748157, -0.491177780418704, -0.755094199748157, 0.212599337793171, 0.212599337793171)): replacement has 96 rows, data has 103
trs_plot_rwl(rwl_data, color = col_vec, zscore = FALSE)