graph_dif: Function focuses on calculating and plotting the lagged...

View source: R/graph_dif.R

graph_difR Documentation

Function focuses on calculating and plotting the lagged difference across a time series.

Description

The lagged differences across a time series at a certain degree dif_lag is taken primarily to transform the series from a non-stationary to stationary process. Function returns a multi-paneled plot of the observed time series (optional), along with a plot for the series' lagged differences. The actual difference values are also returned in a data.frame.

Usage

graph_dif(
  df = NULL,
  time_col = NULL,
  value_col = NULL,
  dif_lag = 1,
  title = NULL,
  x_title = NULL,
  y_title = NULL,
  x_limits = NULL,
  x_major_breaks = waiver(),
  x_major_date_breaks = waiver(),
  x_date_labels = waiver(),
  y_limits = NULL,
  y_major_breaks = waiver(),
  show_pts = TRUE,
  show_obs = TRUE,
  show_major_grids = TRUE,
  show_minor_grids = TRUE,
  col_width = 18,
  row_height = 5,
  display_plot = TRUE,
  png_file_path = NULL
)

Arguments

df

A data.frame containing a time series with both a value and time column.

time_col

Names the column from df for the time values. Values can be numeric or Date/POSIXct.

value_col

Names the numeric column from df for time series values.

dif_lag

An integer that sets the lag of difference to use.

title

A string that defines an overall title to the pair of plots.

x_title

A string that sets the x axis title.

y_title

A string that sets the y 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".

y_limits

A numeric 2 element vector that sets the minimum and maximum for the difference y axis. Use NA to refer to the existing minimum and maximum.

y_major_breaks

A numeric vector or function that defines the exact major tic locations for the difference y axis'.

show_pts

A logical which if FALSE will plot only the lines.

show_obs

A logical which if FALSE hides the plot of observations.

show_major_grids

A logical that controls the appearance of major grids.

show_minor_grids

A logical that controls the appearance of minor grids.

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.

png_file_path

A character string with the directory and file name to produce a png image of the plot.

Details

The 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

Returning a named list with:

  1. "diff_df" – A data frame with column variables for time "DateTime" and the difference values "Value".

  2. "plots" – A multi-paneled TableGrob object plotting the differences and optionally the observed series. 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.