Learn R Programming

TSplotly (version 1.1.1)

ADDline: <U+2018>ADDline<U+2019>

Description

create a list of line data based on ARIMA(X) predicted result or ts function result(i.e. time series data)

Usage

ADDline(ARIMAmodel = NULL, XREG = NULL, TS = NULL, linetype = "TS",
  Name = NULL)

Arguments

ARIMAmodel

ARIMA model created by function auto.arima()

XREG

if using ARIMAX model, put in the regularized X matrix

TS

data created by ts() function

linetype

"TS" for time series data, "ARIMA" for ARIMA(X) predicted data

Name

title for this line

Value

a list contains 4 elements:

X

data put in parameter "x" of plot_ly function

TEXT

rename the lable of variable X

Y

data put in parameter "y" of plot_ly function

NAME

title of the new line

Details

This function ADDline is used to conduct a data transformation. It can take in original time-series data generated by function ts or fitted ARIMA(X) model generated by function auto.arima then take out four elements from those result to create a list which contains content that can be put in function add_lines or add_trace. So that we could add new lines in our plotly plot more easily.

Examples

Run this code
# NOT RUN {
require(forecast)
require(zoo)
require(plotly)

#Firstly create a base plotly plot
Tempplot<-TSplot(48,modArima_train,as.matrix(X_test),title_size = 8,
ts_original = "Original time series",ts_forecast = "Predicted time series")

# Generate a new line with ADDline function
newline<-ADDline(TS = MCSI_Data_monthAvg_ts_Y_test,linetype = "TS",Name = "Original Result")

## Put the new line into our plot
Tempplot%>%
  add_lines(x=newline$X,text=newline$TEXT,y=newline$Y,name=newline$NAME,line=list(color="grey"))

# }

Run the code above in your browser using DataLab