graph_decompose: Function plots an observed time series along with its...

View source: R/graph_decompose.R

graph_decomposeR Documentation

Function plots an observed time series along with its decomposed seasonal, trend, and irregular components

Description

Function uses decompose from the stats package to plot the series' observed values, seasonal, trend, and irregular components using moving averages. User can set the seasonal component as additive or multiplicative.

Usage

graph_decompose(
  series_ts = NULL,
  type_comp = "additive",
  title = NULL,
  x_title = NULL,
  x_limits = NULL,
  x_major_breaks = waiver(),
  x_major_date_breaks = waiver(),
  x_date_labels = waiver(),
  col_width = 18,
  row_height = 3.5,
  display_plot = TRUE
)

Arguments

series_ts

A time series (class ts) object.

type_comp

A string that describes the type of seasonal component. Accepted values are "additive" and "multiplicative".

title

A string that defines an overall title to the multi-paneled plot.

x_title

A string that defines the x axis title.

x_limits

A Date/POSIXct 2 element vector that sets the minimum and maximum for the x axis. Use NA to refer to the existing minimum and maximum.

x_major_breaks

A Date/POSIXct vector or function that defines the exact major tic locations along the x axis.

x_major_date_breaks

For Date/POSIXct, a string containing the number and date unit for major breaks. Examples: "1 year", "4 sec", "3 month", "2 week".

x_date_labels

For Date/POSIXct, a string containing the format codes for the x axis date format. This can be a strftime format for each x axis tic date label. Examples: "%Y-%m", "%Y/%b/%d", "%H-%M-%S".

col_width

An integer that sets the width of each plot column in centimeters.

row_height

An integer that sets the height of each plot column in centimeters.

display_plot

A logical that if TRUE displays the plot.

Details

Function uses the RplotterPkg::multi_panel_grid package to draw the multi-paneled plot.

if display_plot is TRUE then the plots will be displayed. If display_plot is FALSE then the function returns a named list that includes a plot object which can be displayed from the console by entering:

  1. grid::grid.newpage()

  2. grid::grid.draw(plot object)

Value

Returns a named list with:

  1. "decompose_dt" – A data.frame and data.table with column values for the observed series, time, seasonal, trend, and random.

  2. "plots" – A multi-paneled TableGrob object containing line plots of the series' observed values, trend, seasonal, and random values across time. Use grid::grid.draw(plots) to display the plots.

Author(s)

Rick Dean


deandevl/RtsaPkg documentation built on Oct. 5, 2023, 5:23 p.m.