Learn R Programming

TSplotly (version 1.1.1)

TSplot: 'TSplot'

Description

Plotly method working on time series analysis. Work only for month & year dataset(i.e. dataset that can satisfy the format required by function as.yearmon from package zoo)

Usage

TSplot(origin_t, ARIMAmodel, XREG = NULL, NEWtitle = "Result",
  Ylab = "Value", Xlab = "Time(Month/Year)",
  ts_original = "original time series",
  ts_forecast = "forecasted time series", title_size = 10)

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

ts_original

label for original time series line

ts_forecast

label for forecasted time series line

title_size

size of the title

Value

a plot result created by plot_ly() function

Details

The function TSplot 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.

Examples

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

# Creating time series data
MCSI_Data_monthAvg_ts_Y <- ts(Y, start=c(1978,1), end=c(2018, 12), frequency = 12)

# Applying ARIMAX model
modArima <- auto.arima(MCSI_Data_monthAvg_ts_Y, xreg=X)

# Creating plot_ly results
## 48 means that there will be 48 periods from the original
## time series dataset that is included in the plot result.
## You could also change this to "all" to see all original dataset in a single plot.
# }
# NOT RUN {
TSplot(48,modArima,X_new,title_size = 8,ts_original = "Original time series",
ts_forecast = "Predicted time series")
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab