Creates a time series plot of a calculated biodiversity indicator, with an optional smoothed trendline, and visualizes uncertainty.
Usage
plot_ts(
x,
min_year = NULL,
max_year = NULL,
title = "auto",
auto_title = NULL,
y_label_default = NULL,
suppress_y = FALSE,
smoothed_trend = TRUE,
linecolour = NULL,
linealpha = 0.8,
ribboncolour = NULL,
ribbonalpha = 0.2,
error_alpha = 1,
trendlinecolour = NULL,
trendlinealpha = 0.5,
envelopecolour = NULL,
envelopealpha = 0.2,
smooth_cialpha = 1,
point_line = c("point", "line"),
pointsize = 2,
linewidth = 1,
ci_type = c("error_bars", "ribbon"),
error_width = 1,
error_thickness = 1,
smooth_linetype = c("solid", "dashed", "dotted", "dotdash", "longdash", "twodash"),
smooth_linewidth = 1,
smooth_cilinewidth = 1,
gridoff = FALSE,
x_label = NULL,
y_label = NULL,
x_expand = NULL,
y_expand = NULL,
x_breaks = 10,
y_breaks = 6,
wrap_length = 60
)
Arguments
- x
An 'indicator_ts' object containing a time series of indicator values.
- min_year
(Optional) Earliest year to include in the plot.
- max_year
(Optional) Latest year to include in the plot.
- title
Plot title. Replace "auto" with your own title if you want a custom title or if calling the function manually.
- auto_title
Text for automatic title generation, provided by an appropriate S3 method (if calling the function manually, leave as NULL).
- y_label_default
Default label for the y-axis, provided by an appropriate S3 method (if calling the function manually, leave as NULL).
- suppress_y
If TRUE, suppresses y-axis labels.
- smoothed_trend
If TRUE, plot a smoothed trendline over time (
stats::loess()
).- linecolour
(Optional) Colour for the indicator line or points. Default is darkorange.
- linealpha
Transparency for indicator line or points. Default is 0.8.
- ribboncolour
(Optional) Colour for the bootstrapped confidence intervals. Default is goldenrod1. Set to "NA" if you don't want to plot the CIs.
- ribbonalpha
Transparency for indicator confidence interval ribbon (if ci_type = "ribbon"). Default is 0.2.
- error_alpha
Transparency for indicator error bars (if ci_type = "error_bar"). Default is 1.
- trendlinecolour
(Optional) Colour for the smoothed trendline. Default is blue.
- trendlinealpha
Transparency for the smoothed trendline. Default is 0.5.
- envelopecolour
(Optional) Colour for the uncertainty envelope. Default is lightsteelblue.
- envelopealpha
Transparency for the smoothed trendline envelope. Default is 0.2.
- smooth_cialpha
Transparency for the smoothed lines forming the edges of the trendline envelope. Default is 1.
- point_line
Whether to plot the indicator as a line or a series of points. Options are "line" or "point". Default is "point".
- pointsize
Size of the points if point_line = "point". Default is 2.
- linewidth
Width of the line if point_line = "line". Default is 1.
- ci_type
Whether to plot bootstrapped confidence intervals as a "ribbon" or "error_bars". Default is "error_bars".
- error_width
Width of error bars if ci_type = "error_bars". Default is 1. Note that unlike the default 'width' parameter in geom_errorbar, 'error_width' is NOT dependent on the number of data points in the plot. It is automatically scaled to account for this. Therefore the width you select will be consistent relative to the plot width even if you change 'min_year' and 'max_year'.
- error_thickness
Thickness of error bars if ci_type = "error_bars". Default is 1.
- smooth_linetype
Type of line to plot for smoothed trendline. Default is "solid".
- smooth_linewidth
Line width for smoothed trendline. Default is 1.
- smooth_cilinewidth
Line width for smoothed trendline confidence intervals. Default is 1.
- gridoff
If TRUE, hides gridlines.
- x_label
Label for the x-axis.
- y_label
Label for the y-axis.
- x_expand
(Optional) Expansion factor to expand the x-axis beyond the data. Left and right values are required in the form of c(0.1, 0.2). Default is c(0,0).
- y_expand
(Optional) Expansion factor to expand the y-axis beyond the data. Lower and upper values are required in the form of c(0.1, 0.2). Default is c(0,0).
- x_breaks
Integer giving desired number of breaks for x axis. (May not return exactly the number requested.)
- y_breaks
Integer giving desired number of breaks for y axis. (May not return exactly the number requested.)
- wrap_length
Maximum title length before wrapping to a new line.
Value
A ggplot object representing the biodiversity indicator time series plot. Can be customized using ggplot2 functions.
Examples
# default colours:
plot_ts(example_indicator_ts1,
y_label = "Species Richness",
title = "Observed Species Richness: Mammals in Denmark")
# custom colours:
plot_ts(example_indicator_ts1,
y_label = "Species Richness",
title = "Observed Species Richness: Mammals in Denmark",
linecolour = "thistle",
trendlinecolour = "forestgreen",
envelopecolour = "lightgreen")