[R] Problem in conversion of regulate time series and forecasting using Date Time [Timestamp values]:R

Dhivya Narayanasamy dhiv.shreya at gmail.com
Thu Apr 27 07:40:50 CEST 2017

```Hi,
I have a data frame "gg", that looks like this:

timestamps      value
1 2017-04-25 16:52:00 -0.4120000
2 2017-04-25 16:53:00 -0.4526667
3 2017-04-25 16:54:00 -0.4586667
4 2017-04-25 16:55:00 -0.4606667
5 2017-04-25 16:56:00 -0.5053333
6 2017-04-25 16:57:00 -0.5066667

I need to plot this as a Time series data to do forecasting. The steps are
as follows:

1) gg\$timestamps <- as.POSIXct(gg\$timestamps, format = "%Y-%m-%d %H-%M-%S")
#changing "Timestamps" column 'factor' to 'as.POSIXct'.

2) gg.ts <- xts(x=gg\$value, order.by = gg\$timestamps) #converting the
dataframe to time series (Non Regular Time series)

3) fitting <- auto.arima(gg.ts) #fitting the time series model using
auto.arima

4) fore <- forecast(fitting, h=30, level = c(80,95))  #Forecasting

5) I am using plotly to this forecast model (Inspired from here :
https://plot.ly/r/graphing-multiple-chart-types/#plotting-forecast-objects)

plot_ly() %>%
add_lines(x = time(gg.ts), y = gg.ts,
color = I("black"), name = "observed") %>%
add_ribbons(x = time(fore\$mean), ymin = fore\$lower[, 2], ymax =
fore\$upper[, 2],
color = I("gray95"), name = "95% confidence") %>%
add_ribbons(x = time(fore\$mean), ymin = fore\$lower[, 1], ymax =
fore\$upper[, 1],
color = I("gray80"), name = "80% confidence") %>%
add_lines(x = time(fore\$mean), y = fore\$mean, color = I("blue"), name =
"prediction")

The plot comes out wrong: 1) x axis labels are wrong. It shows some
irrelevant values on axis. 2) the plot is not coming out.
Also I tried to convert "gg.ts" to a regulate time series which throws
error :

> gg.xts <- ts(gg.ts, frequency = '1', start = ('2017-04-25 16:52:00'))
Error in 1/frequency : non-numeric argument to binary operator