TSplot_gen: 'TSplot_gen'

Description Usage Arguments Details Value Author(s) Examples

View source: R/TSplot_gen.R

Description

Plotly method working on time series analysis. This is a more general function that can work on any fitted ARIMA(X) model with any time format. Also, a list of time series data can be applied into this function so that new time lines can be directly drawn in the plot without referring to the result of ADDline function.

Usage

1
2
3
4
5
6
TSplot_gen(origin_t, ARIMAmodel, XREG = NULL, NEWtitle = "Result",
  Ylab = "Value", Xlab = "Time", plot_labels = NULL,
  ts_original = "original time series",
  ts_forecast = "forecasted time series", title_size = 10,
  ts_list = "empty", ts_labels = NULL, ts_names = NULL,
  COLO = NULL)

Arguments

origin_t

Number of periods of original time series data you wish to include in the plot write all if all periods should be included

ARIMAmodel

ARIMA model created by function auto.arima()

XREG

if using ARIMAX model, put in the regularized X matrix

NEWtitle

title for this plot

Ylab

label of Y axis

Xlab

label of X axis

plot_labels

To include a specific labels for each time point of all training time series data and predicted ARIMA(X) result. A vector should be applied to this parameter that has the same length of chosen periods of training time series data (i.e. parameter origin_t) along with predicted time series periods.

ts_original

label for original time series line

ts_forecast

label for forecasted time series line

title_size

size of the title

ts_list

applying this function can help you draw more time lines into the original plot. A list should be applied to this parameter which contains all extra time series data that you wish to draw on the original plot. Each element on this list should be created by function ts()

ts_labels

when drawing extra time lines with parameter ts_list. You could create specific labels for each time points. A list with the same shape of list in ts_list should be applied. Each element in this list should contain time labels corresponding with the list in ts_list

ts_names

Creating labels for each extra time lines you draw. Labels will appear on the legend of the plot.

COLO

Specifying colors for each new lines that is drawn.

Details

The function TSplot_gen is based on package plotly. It applies plot_ly function to create interactive plot for time-series analysis result. It requires a fitted model by function auto.arima. If you are fitting an ARIMA model with external regressors (i.e. Xreg), then you must put inside the external regressors again.

Value

a plot result created by plot_ly() function

Author(s)

SOCR team <http://socr.umich.edu/people/>

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# Creating time labels
require(zoo)
require(forecast)
require(plotly)

tl1<-as.yearmon(time(modArima_train$x))[(length(modArima_train$x)-48+1):length(modArima_train$x)]
tl2<-as.yearmon(time(forecast(modArima_train,xreg = as.matrix(X_test))$mean))
tl<-as.character(c(tl1,tl2))
# Creating list and other information for new lines
TSlist<-list(MCSI_Data_monthAvg_ts_Y_test)
TSlabel<-list(as.character(as.yearmon(time(TSlist[[1]]))))
TSname<-c("Original result")
# Put them into related parameters
TSplot_gen(48,modArima_train,as.matrix(X_test),title_size = 8,ts_original = "Original time series",
        ts_forecast = "Predicted time series",plot_labels = tl, #labels of original plot
        ts_list = TSlist,ts_names = TSname,ts_labels = TSlabel,COLO = "black")

TSplotly documentation built on Aug. 2, 2019, 5:04 p.m.