ts_sma_plot: Simple Moving Average Plot

View source: R/ts-sma-plot.R

ts_sma_plotR Documentation

Simple Moving Average Plot

Description

This function will take in a value column and return any number n moving averages.

Usage

ts_sma_plot(
  .data,
  .date_col,
  .value_col,
  .sma_order = 2,
  .func = mean,
  .align = "center",
  .partial = FALSE
)

Arguments

.data

The data that you are passing, must be a data.frame/tibble.

.date_col

The column that holds the date.

.value_col

The column that holds the value.

.sma_order

This will default to 1. This can be a vector like c(2,4,6,12)

.func

The unquoted function you want to pass, mean, median, etc

.align

This can be either "left", "center", "right"

.partial

This is a bool value of TRUE/FALSE, the default is TRUE

Details

This function will accept a time series object or a tibble/data.frame. This is a simple wrapper around timetk::slidify_vec(). It uses that function to do the underlying moving average work.

It can only handle a single moving average at a time and therefore if multiple are called for, it will loop through and append data to a tibble object.

Value

Will return a list object.

Author(s)

Steven P. Sanderson II, MPH

Examples

df <- ts_to_tbl(AirPassengers)
out <- ts_sma_plot(df, date_col, value, .sma_order = c(3,6))

out$data

out$plots$static_plot



spsanderson/healthyR.ts documentation built on Jan. 19, 2024, 10:02 p.m.