简体   繁体   English

如何使用具有'Index'和Datetime值的时间序列数据以绘图方式绘制预测

[英]How to plot forecast using plotly for time series data having 'Index' with Datetime value

I want to plot forecast of a time series using plotly. 我想使用plotly绘制时间序列的预测。 But my index of the timeseries consists of timestamp [Date Time] Values. 但是我的时间序列索引由时间戳[Date Time]值组成。 which makes difficult to plot the forecast part. 这使得很难绘制预测部分。

    > qxts
                          [,1]
2017-04-25 16:52:00 -0.4120000
2017-04-25 16:53:00 -0.4526667
2017-04-25 16:54:00 -0.4586667
2017-04-25 16:55:00 -0.4606667
2017-04-25 16:56:00 -0.5053333
2017-04-25 16:57:00 -0.5066667
2017-04-25 16:58:00 -0.5100000
2017-04-25 16:59:00 -0.4986667
2017-04-25 17:00:00 -0.5026667
2017-04-25 17:01:00 -0.5053333
2017-04-25 17:02:00 -0.5020000
2017-04-25 17:03:00 -0.5066667
2017-04-25 17:04:00 -0.5080000
2017-04-25 17:05:00 -0.5040000
2017-04-25 17:06:00 -0.5013333
2017-04-25 17:07:00 -0.5020000
2017-04-25 17:08:00 -0.5020000
2017-04-25 17:09:00 -0.5040000
2017-04-25 17:10:00 -0.5046667
2017-04-25 17:11:00 -0.5053333
2017-04-25 17:12:00 -0.5013333
2017-04-25 17:13:00 -0.5033333
2017-04-25 17:14:00 -0.4966667
2017-04-25 17:15:00 -0.5040000
2017-04-25 17:16:00 -0.4980000
2017-04-25 17:17:00 -0.3893333
2017-04-25 17:18:00 -0.3640000
2017-04-25 17:19:00 -0.3653333
2017-04-25 17:20:00 -0.3586667
2017-04-25 17:21:00 -0.3600000
2017-04-25 17:22:00 -0.3553333
2017-04-25 17:23:00 -0.3653333
2017-04-25 17:24:00 -0.3606667
2017-04-25 17:25:00 -0.3640000
2017-04-25 17:26:00 -0.3546667
2017-04-25 17:27:00 -0.3700000
2017-04-25 17:28:00 -0.3653333
2017-04-25 17:29:00 -0.3673333
2017-04-25 17:30:00 -0.3966667
2017-04-25 17:31:00 -0.4693333
2017-04-25 17:32:00 -0.4586667
2017-04-25 17:33:00 -0.4640000
2017-04-25 17:34:00 -0.4573333
2017-04-25 17:35:00 -0.4646667
2017-04-25 17:36:00 -0.4680000
2017-04-25 17:37:00 -0.4688000
2017-04-25 17:38:00 -0.4673333
2017-04-25 17:39:00 -0.4606667
2017-04-25 17:40:00 -0.4653333
2017-04-25 17:41:00 -0.4720000
2017-04-25 17:42:00 -0.4533333
2017-04-25 17:43:00 -0.4660000
2017-04-25 17:44:00 -0.4646667
2017-04-25 17:45:00 -0.4593333
2017-04-25 17:46:00 -0.4646667
2017-04-25 17:47:00 -0.4580000
2017-04-25 17:48:00 -0.4646667
2017-04-25 17:49:00 -0.4740000
2017-04-25 17:50:00 -0.4173333
2017-04-25 17:51:00 -0.4640000
2017-04-25 17:52:00 -0.4600000
2017-04-25 17:53:00 -0.4686667
2017-04-25 17:54:00 -0.4720000
2017-04-25 17:55:00 -0.4653333
2017-04-25 17:56:00 -0.4720000
2017-04-25 17:57:00 -0.4626667
2017-04-25 17:58:00 -0.4624000
2017-04-25 17:59:00 -0.4653333
2017-04-25 18:00:00 -0.4673333
2017-04-25 18:01:00 -0.4600000
2017-04-25 18:02:00 -0.4646667
2017-04-25 18:03:00 -0.4613333
2017-04-25 18:04:00 -0.4660000
2017-04-25 18:05:00 -0.4620000
2017-04-25 18:06:00 -0.4620000
2017-04-25 18:07:00 -0.4666667
2017-04-25 18:08:00 -0.4573333
2017-04-25 18:09:00 -0.4660000
2017-04-25 18:10:00 -0.4640000
2017-04-25 18:11:00 -0.4640000
2017-04-25 18:12:00 -0.4886667
2017-04-25 18:13:00 -0.5433333
2017-04-25 18:14:00 -0.4893333
2017-04-25 18:15:00 -0.3600000
2017-04-25 18:16:00  0.0000000
2017-04-25 18:17:00  0.0000000
2017-04-25 18:18:00  0.0000000
2017-04-25 18:19:00  0.0000000
2017-04-25 18:20:00  0.0000000
2017-04-25 18:21:00  0.0000000
2017-04-25 18:22:00  0.0000000
2017-04-25 18:23:00  0.0000000
2017-04-25 18:24:00  0.0000000
2017-04-25 18:25:00  0.0000000
2017-04-25 18:26:00  0.0000000
2017-04-25 18:27:00  0.0000000
2017-04-25 18:28:00  0.0000000
2017-04-25 18:29:00  0.0000000
2017-04-25 18:30:00  0.0000000
2017-04-25 18:31:00  0.0000000
2017-04-25 18:32:00  0.0000000
2017-04-25 18:33:00  0.0000000
2017-04-25 18:34:00  0.0000000
2017-04-25 18:35:00  0.0000000
2017-04-25 18:36:00 -0.3573333
2017-04-25 18:37:00 -0.4646667
2017-04-25 18:38:00 -0.3360000
2017-04-25 18:39:00 -0.4453333
2017-04-25 18:40:00 -0.4933333
2017-04-25 18:41:00 -0.4446667
2017-04-25 18:42:00 -0.3253333
2017-04-25 18:43:00 -0.6020000
2017-04-25 18:44:00 -0.3304000
2017-04-25 18:45:00 -0.3946667
2017-04-25 18:46:00 -0.4066667
2017-04-25 18:47:00 -0.4066667
2017-04-25 18:48:00 -0.5253333
2017-04-25 18:49:00 -0.5520000
2017-04-25 18:50:00 -0.6973333
2017-04-25 18:51:00 -0.5260000
2017-04-25 18:52:00 -0.5653333
2017-04-25 18:53:00 -0.4514286
2017-04-25 18:54:00 -0.3973333
2017-04-25 18:55:00 -0.5920000
2017-04-25 18:56:00 -0.4912000
2017-04-25 18:57:00 -0.4313333
2017-04-25 18:58:00 -0.1973333
2017-04-25 18:59:00 -0.5460000
2017-04-25 19:00:00 -0.4960000
2017-04-25 19:01:00 -0.4595000
2017-04-25 19:02:00 -0.4592000
2017-04-25 19:03:00 -0.4537143
2017-04-25 19:04:00 -0.4553333
2017-04-25 19:05:00 -0.4613333
2017-04-25 19:06:00 -0.4620000
2017-04-25 19:07:00 -0.4573333
2017-04-25 19:08:00 -0.4606667
2017-04-25 19:09:00 -0.4560000
2017-04-25 19:10:00 -0.4593333
2017-04-25 19:11:00 -0.4580000
2017-04-25 19:12:00 -0.4568000
2017-04-25 19:13:00 -0.4554286
2017-04-25 19:14:00 -0.4546667
2017-04-25 19:15:00 -0.4540000
2017-04-25 19:16:00 -0.4526667
2017-04-25 19:17:00 -0.4640000
2017-04-25 19:18:00 -0.4566667
2017-04-25 19:19:00 -0.4544000
2017-04-25 19:20:00 -0.4566667
2017-04-25 19:21:00 -0.4546667
2017-04-25 19:22:00 -0.4600000
2017-04-25 19:23:00 -0.4584000
2017-04-25 19:24:00 -0.4593333
2017-04-25 19:25:00 -0.3946667
2017-04-25 19:26:00 -0.3673333
2017-04-25 19:27:00 -0.2824000
2017-04-25 19:28:00 -0.3446667
2017-04-25 19:29:00 -0.4646667
2017-04-25 19:30:00 -0.4433333
2017-04-25 19:31:00 -0.3392000
2017-04-25 19:32:00 -0.3326667
2017-04-25 19:33:00 -0.3633333
2017-04-25 19:34:00 -0.4360000
2017-04-25 19:35:00 -0.5180000
2017-04-25 19:36:00 -0.1593333
2017-04-25 19:37:00 -0.2493333
2017-04-25 19:38:00 -0.4336000
2017-04-25 19:39:00 -0.4626667
2017-04-25 19:40:00 -0.4100000
2017-04-25 19:41:00 -0.3573333
2017-04-25 19:42:00 -0.3616000
2017-04-25 19:43:00 -0.4946667
2017-04-25 19:44:00 -0.5220000
2017-04-25 19:45:00 -0.2940000
2017-04-25 19:46:00 -0.4528000
2017-04-25 19:47:00 -0.4740000
2017-04-25 19:48:00 -0.3426667
2017-04-25 19:49:00 -0.5368000
2017-04-25 19:50:00 -0.4233333
2017-04-25 19:51:00 -0.4986667
2017-04-25 19:52:00 -0.4393333
2017-04-25 19:53:00 -0.4648000
2017-04-25 19:54:00 -0.3686667
2017-04-25 19:55:00 -0.2673333
2017-04-25 19:56:00 -0.3033333
2017-04-25 19:57:00 -0.2128000
2017-04-25 19:58:00 -0.3980000
2017-04-25 19:59:00 -0.4446667
2017-04-25 20:00:00 -0.6368000
2017-04-25 20:01:00 -0.3373333
2017-04-25 20:02:00 -0.2600000

forecasting my time series 预测我的时间序列

fit.xts <- auto.arima(qxts)
fore.xts <- forecast(fit.xts, h=10)

plotting the forecasting 绘制预测

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

This gives empty plot. 这给出了空图。 Can someone help me? 有人能帮我吗? I have been looking for answers for two days. 我一直在寻找答案两天。

dput(qxts) structure(c(-0.4120000005, -0.452666665083333, -0.458666667316667, -0.460666666416667, -0.505333344133333, -0.506666670233333, -0.50999999045, -0.498666668933333, -0.502666672066667, -0.505333344133333, -0.50200000405, -0.506666680166667, -0.508000006266667, -0.5040000081, -0.501333341, -0.50200000405, -0.502000009016667, -0.504000003133333, -0.50466667115, -0.505333344133333, -0.501333341, -0.503333340083333, -0.496666664883333, -0.5040000081, -0.49799999595, -0.389333337533333, -0.3640000075, -0.365333338566667, -0.3586666733, -0.3599999994, -0.355333338183333, -0.365333338566667, -0.360666667416667, -0.3640000075, -0.3546666652, -0.369999999783333, -0.3653333336, -0.36733333765, -0.396666670833333, -0.469333335766667, -0.4586666673, -0.4639999916, -0.457333331283333, -0.4646666596, -0.4680000047, -0.4687999964, -0.467333336683333, -0.460666661433333, -0.4653333326, -0.4720000029, -0.453333328166667, -0.466000000616667, -0.4646666646, -0.45933333535, -0.464666659633333, -0 dput(qxts)结构(c(-0.4120000005,-0.452666665083333,-0.458666667316667,-0.460666666416667,-0.505333344133333,-0.506666670233333,-0.50999999045,-0.498666668933333,-0.502666672066667,-0.505333344133333,-0.5020000080,166,-66781 -0.501333341,-0.50200000405,-0.502000009016667,-0.504000003133333,-0.50466667115,-0.505333344133333,-0.501333341,-0.503333340083333,-0.496666664883333,-0.5040000081,-0.49799999595,-0.3893333375666333,-0.3640000075,-0.3.33333385659633 ,-0.365333338566667,-0.360666667416667,-0.3640000075,-0.3546666652,-0.369999999783333,-0.3653333336,-0.36733333765,-0.396666670833333,-0.469333335766667,-0.4586666673,-0.4639999916,-0.457333331283333,-0.4646666596,-0.4680687683 0.460666661433333,-0.4653333326,-0.4720000029,-0.453333328166667,-0.466000000616667,-0.4646666646,-0.45933333535,-0.464666659633333,-0 .4579999993, -0.464666669566667, -0.473999996983333, -0.417333334666667, -0.46400000155, -0.4599999934, -0.46866666775, -0.47200000288, -0.465333337583333, -0.4719999979, -0.462666660516667, -0.46240000126, -0.465333322666667, -0.4673333317, -0.459999993416667, -0.464666659616667, -0.461333329466667, -0.46599999565, -0.461999997483333, -0.461999992516667, -0.466666663683333, -0.457333336283333, -0.46600000065, -0.463999996566667, -0.46400000155, -0.488666658566667, -0.543333326766667, -0.489333341533333, -0.3600000143, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -0.3573333323, -0.464666662133333, -0.3360000037, -0.445333333066667, -0.49333334465, -0.444666661316667, -0.325333339483333, -0.60199998815, -0.33039999454, -0.394666674216667, -0.406666671233333, -0.4066666588, -0.52533333005, -0.552000006066667, -0.6973333458, -0.526000003, -0.565333336583333, -0.451428575185714, -0.3973333314, -0.591999994871429, -0.49120000004, -0.4313333432, -0.197333325966667, -0.54599999 .4579999993,-0.464666669566667,-0.473999996983333,-0.417333334666667,-0.46400000155,-0.4599999934,-0.46866666775,-0.47200000288,-0.465333337583333,-0.4719999979,-0.462666660516667,-0.46240000126,-0.465333322666667,-0.40.3333646, ,-0.46599999565,-0.461999997483333,-0.461999992516667,-0.466666663683333,-0.457333336283333,-0.46600000065,-0.463999996566667,-0.46400000155,-0.488666658566667,-0.543333326766667,-0.489333341533333,-0.3600000143、0、0、0、0、0、0、0 ,0,0,0,0,0,0,0,0,0,0,0,0,0,-0.3573333323,-0.464666662133333,-0.3360000037,-0.445333333066667,-0.49333334465,-0.444666661316667,-0.325333339483333,-0.60199998815 ,-0.33039999454,-0.394666674216667,-0.406666671233333,-0.4066666588,-0.52533333005,-0.552000006066667,-0.6973333458,-0.526000003,-0.565333336583333,-0.451428575185714,-0.3973333314,-0.5919999999994871429,-0.49120000004,-0.3313333459966 8833333, -0.49600000976, -0.4595000035875, -0.45920000072, -0.453714281285714, -0.455333337166667, -0.461333334433333, -0.461999992533333, -0.457333331283333, -0.4606666664, -0.456000005183333, -0.4593333254, -0.4579999993, -0.45679999586, -0.455428570485714, -0.454666664183333, -0.453999991183333, -0.452666665083333, -0.464000001533333, -0.456666668216667, -0.45439999696, -0.45666666825, -0.454666664166667, -0.459999998383333, -0.45840000508, -0.459333330366667, -0.394666661816667, -0.367333332983333, -0.2823999971, -0.3446666648, -0.464666659633333, -0.443333327766667, -0.33920000494, -0.332666660333333, -0.363333340716667, -0.43599999546, -0.518000001716667, -0.15933333585, -0.2493333357, -0.43359999356, -0.462666669166667, -0.410000008833333, -0.357333337883333, -0.3615999937, -0.494666665783333, -0.52200000485, -0.29400000225, -0.4527999997, -0.474000004416667, -0.342666663233333, -0.53680000306, -0.423333331933333, -0.498666671416667, -0.439333344516667, -0.46480000914, -0.368666 8833333,-0.49600000976,-0.4595000035875,-0.45920000072,-0.453714281285714,-0.455333337166667,-0.461333334433333,-0.461999992533333,-0.457333331283333,-0.4606666664,-0.456000005183333,-0.4593333254,-0.4579999993,-0.45670.49999, -0.452666665083333,-0.464000001533333,-0.456666668216667,-0.45439999696,-0.45666666825,-0.454666664166667,-0.459999998383333,-0.45840000508,-0.459333330366667,-0.39466666181616667--0.367333332983333,-0.2823999971,-0.30.3666666,964 ,-0.363333340716667,-0.43599999546,-0.518000001716667,-0.15933333585,-0.2493333357,-0.43359999356,-0.462666669166667,-0.410000008833333,-0.357333337883333,-0.3615999937,-0.494666665783333,-0.52200000485,-0.29400000225,-0.4527999997,-632 0.53680000306,-0.423333331933333,-0.498666671416667,-0.439333344516667,-0.46480000914,-0.368666 668733333, -0.2673333399, -0.303333333366667, -0.21279999912, -0.398000004383333, -0.444666676216667, -0.63679999114, -0.337333336466667, -0.2599999905 ), .Dim = c(191L, 1L), index = structure(c(1493139120, 1493139180, 1493139240, 1493139300, 1493139360, 1493139420, 1493139480, 1493139540, 1493139600, 1493139660, 1493139720, 1493139780, 1493139840, 1493139900, 1493139960, 1493140020, 1493140080, 1493140140, 1493140200, 1493140260, 1493140320, 1493140380, 1493140440, 1493140500, 1493140560, 1493140620, 1493140680, 1493140740, 1493140800, 1493140860, 1493140920, 1493140980, 1493141040, 1493141100, 1493141160, 1493141220, 1493141280, 1493141340, 1493141400, 1493141460, 1493141520, 1493141580, 1493141640, 1493141700, 1493141760, 1493141820, 1493141880, 1493141940, 1493142000, 1493142060, 1493142120, 1493142180, 1493142240, 1493142300, 1493142360, 1493142420, 1493142480, 1493142540, 1493142600, 1493142660, 1493142720, 1493142780, 1493142840, 1493142900, 1493142960, 1493143020, 1493143080, 1 668733333,-0.2673333399,-0.303333333366667,-0.21279999912,-0.398000004383333,-0.444666676216667,-0.63679999114,-0.337333336466667,-0.2599999905).Dim = c(191L,1L),索引=结构(c(149(3139120),1493139180,1493139240,1493139240) ,1493139360,1493139420,1493139480,1493139540,1493139600,1493139660,1493139720,1493139780,1493139840,1493139900,1493139960,1493140020、1493140080,1493140140,1493140200,1493140260,1493140320,1493140380 1493140140,1493140460 1490140140 ,1493140860、1493140920、1493140980、1493141040、1493141100、1493141160、1493141220、1493141280、1493141340、1493141400、1493141460、1493141520、1493141580、1493141640、1493141700、1493141760、1493141820、1493141880、1493141142、1493142140142 1294141931 ,1493142360,1493142420,1493142480,1493142540,1493142600,1493142660,1493142720,1493142780,1493142840,1493142900,1493142960,1493143020,1493143080、1 493143140, 1493143200, 1493143260, 1493143320, 1493143380, 1493143440, 1493143500, 1493143560, 1493143620, 1493143680, 1493143740, 1493143800, 1493143860, 1493143920, 1493143980, 1493144040, 1493144100, 1493144160, 1493144220, 1493144280, 1493144340, 1493144400, 1493144460, 1493144520, 1493144580, 1493144640, 1493144700, 1493144760, 1493144820, 1493144880, 1493144940, 1493145000, 1493145060, 1493145120, 1493145180, 1493145240, 1493145300, 1493145360, 1493145420, 1493145480, 1493145540, 1493145600, 1493145660, 1493145720, 1493145780, 1493145840, 1493145900, 1493145960, 1493146020, 1493146080, 1493146140, 1493146200, 1493146260, 1493146320, 1493146380, 1493146440, 1493146500, 1493146560, 1493146620, 1493146680, 1493146740, 1493146800, 1493146860, 1493146920, 1493146980, 1493147040, 1493147100, 1493147160, 1493147220, 1493147280, 1493147340, 1493147400, 1493147460, 1493147520, 1493147580, 1493147640, 1493147700, 1493147760, 1493147820, 1493147880, 1493147940, 1493148000, 1493148060, 14931 493143140、1493143200、1493143260、1493143320、1493143380、1493143440、1493143500、1493143560、1493143620、1493143680、1493143740、1493143800、1493143860、1493143920、1493143980、1493144040、1493144100、1493144160 1294144144 1144144144 1144144144 1144144144 1493144640,1493144700,1493144760,1493144820,1493144880,1493144940,1493145000,1493145060,1493145120,1493145180,1493145240,1493145300,1493145360,1493145420,1493145480,1493145540,1493145600,1493145420,1493145720,1493145720,1493145960,1493145720 1493146140、1493146200、1493146260、1493146320、1493146380、1493146440、1493146500、1493146560、1493146620、1493146680、1493146740、1493146800、1493146860、1493146920、1493146980、1493147040、1493493100100、4933147160、1493147220、1493147220、1493147220、147 1493147640、1493147700、1493147760、1493147820、1493147880、1493147940、1493148000、1493148060、14931 48120, 1493148180, 1493148240, 1493148300, 1493148360, 1493148420, 1493148480, 1493148540, 1493148600, 1493148660, 1493148720, 1493148780, 1493148840, 1493148900, 1493148960, 1493149020, 1493149080, 1493149140, 1493149200, 1493149260, 1493149320, 1493149380, 1493149440, 1493149500, 1493149560, 1493149620, 1493149680, 1493149740, 1493149800, 1493149860, 1493149920, 1493149980, 1493150040, 1493150100, 1493150160, 1493150220, 1493150280, 1493150340, 1493150400, 1493150460, 1493150520), tzone = "", tclass = c("POSIXct", "POSIXt")), class = c("xts", "zoo"), .indexCLASS = c("POSIXct", "POSIXt"), tclass = c("POSIXct", "POSIXt"), .indexTZ = "", tzone = "") 48120,1493148180,1493148240,1493148300,​​1493148360,1493148420,1493148480,1493148540,1493148600,1493148660,1493148720,1493148780,1493148840,1493148900,1493148960,1493149020,1493149080,1493149140,1493149149、1493149149,1493149149 1493149620、1493149680、1493149740、1493149800、1493149860、1493149920、1493149980、1493150040、1493150100、1493150160、1493150220、1493150280、1493150340、1493150400、1493150460、1493150520),tzone =“”,tclass = c(“ POSIXt”), ),class = c(“ xts”,“ zoo”)、. indexCLASS = c(“ POSIXct”,“ POSIXt”),tclass = c(“ POSIXct”,“ POSIXt”)、. indexTZ =“”,tzone = “”)

You could convert your timestamps via as.POSIXct and then plot it. 您可以通过as.POSIXct转换时间戳,然后将其绘制。 For the forecasts you would also need to supply the dates (in the following example I assumed that the time difference is always equal). 对于预测,您还需要提供日期(在以下示例中,我假设时差始终相等)。

在此处输入图片说明

library(forecast)

qxts = structure(list(y=c(-0.4120000005, -0.452666665083333, -0.458666667316667, -0.460666666416667, -0.505333344133333, -0.506666670233333, -0.50999999045, -0.498666668933333, -0.502666672066667, -0.505333344133333, -0.50200000405, -0.506666680166667, -0.508000006266667, -0.5040000081, -0.501333341, -0.50200000405, -0.502000009016667, -0.504000003133333, -0.50466667115, -0.505333344133333, -0.501333341, -0.503333340083333, -0.496666664883333, -0.5040000081, -0.49799999595, -0.389333337533333, -0.3640000075, -0.365333338566667, -0.3586666733, -0.3599999994, -0.355333338183333, -0.365333338566667, -0.360666667416667, -0.3640000075, -0.3546666652, -0.369999999783333, -0.3653333336, -0.36733333765, -0.396666670833333, -0.469333335766667, -0.4586666673, -0.4639999916, -0.457333331283333, -0.4646666596, -0.4680000047, -0.4687999964, -0.467333336683333, -0.460666661433333, -0.4653333326, -0.4720000029, -0.453333328166667, -0.466000000616667, -0.4646666646, -0.45933333535, -0.464666659633333, -0.4579999993, -0.464666669566667, -0.473999996983333, -0.417333334666667, -0.46400000155, -0.4599999934, -0.46866666775, -0.47200000288, -0.465333337583333, -0.4719999979, -0.462666660516667, -0.46240000126, -0.465333322666667, -0.4673333317, -0.459999993416667, -0.464666659616667, -0.461333329466667, -0.46599999565, -0.461999997483333, -0.461999992516667, -0.466666663683333, -0.457333336283333, -0.46600000065, -0.463999996566667, -0.46400000155, -0.488666658566667, -0.543333326766667, -0.489333341533333, -0.3600000143, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -0.3573333323, -0.464666662133333, -0.3360000037, -0.445333333066667, -0.49333334465, -0.444666661316667, -0.325333339483333, -0.60199998815, -0.33039999454, -0.394666674216667, -0.406666671233333, -0.4066666588, -0.52533333005, -0.552000006066667, -0.6973333458, -0.526000003, -0.565333336583333, -0.451428575185714, -0.3973333314, -0.591999994871429, -0.49120000004, -0.4313333432, -0.197333325966667, -0.545999998833333, -0.49600000976, -0.4595000035875, -0.45920000072, -0.453714281285714, -0.455333337166667, -0.461333334433333, -0.461999992533333, -0.457333331283333, -0.4606666664, -0.456000005183333, -0.4593333254, -0.4579999993, -0.45679999586, -0.455428570485714, -0.454666664183333, -0.453999991183333, -0.452666665083333, -0.464000001533333, -0.456666668216667, -0.45439999696, -0.45666666825, -0.454666664166667, -0.459999998383333, -0.45840000508, -0.459333330366667, -0.394666661816667, -0.367333332983333, -0.2823999971, -0.3446666648, -0.464666659633333, -0.443333327766667, -0.33920000494, -0.332666660333333, -0.363333340716667, -0.43599999546, -0.518000001716667, -0.15933333585, -0.2493333357, -0.43359999356, -0.462666669166667, -0.410000008833333, -0.357333337883333, -0.3615999937, -0.494666665783333, -0.52200000485, -0.29400000225, -0.4527999997, -0.474000004416667, -0.342666663233333, -0.53680000306, -0.423333331933333, -0.498666671416667, -0.439333344516667, -0.46480000914, -0.368666668733333, -0.2673333399, -0.303333333366667, -0.21279999912, -0.398000004383333, -0.444666676216667, -0.63679999114, -0.337333336466667, -0.2599999905 ), 
                      date = c(1493139120, 1493139180, 1493139240, 1493139300, 1493139360, 1493139420, 1493139480, 1493139540, 1493139600, 1493139660, 1493139720, 1493139780, 1493139840, 1493139900, 1493139960, 1493140020, 1493140080, 1493140140, 1493140200, 1493140260, 1493140320, 1493140380, 1493140440, 1493140500, 1493140560, 1493140620, 1493140680, 1493140740, 1493140800, 1493140860, 1493140920, 1493140980, 1493141040, 1493141100, 1493141160, 1493141220, 1493141280, 1493141340, 1493141400, 1493141460, 1493141520, 1493141580, 1493141640, 1493141700, 1493141760, 1493141820, 1493141880, 1493141940, 1493142000, 1493142060, 1493142120, 1493142180, 1493142240, 1493142300, 1493142360, 1493142420, 1493142480, 1493142540, 1493142600, 1493142660, 1493142720, 1493142780, 1493142840, 1493142900, 1493142960, 1493143020, 1493143080, 1493143140, 1493143200, 1493143260, 1493143320, 1493143380, 1493143440, 1493143500, 1493143560, 1493143620, 1493143680, 1493143740, 1493143800, 1493143860, 1493143920, 1493143980, 1493144040, 1493144100, 1493144160, 1493144220, 1493144280, 1493144340, 1493144400, 1493144460, 1493144520, 1493144580, 1493144640, 1493144700, 1493144760, 1493144820, 1493144880, 1493144940, 1493145000, 1493145060, 1493145120, 1493145180, 1493145240, 1493145300, 1493145360, 1493145420, 1493145480, 1493145540, 1493145600, 1493145660, 1493145720, 1493145780, 1493145840, 1493145900, 1493145960, 1493146020, 1493146080, 1493146140, 1493146200, 1493146260, 1493146320, 1493146380, 1493146440, 1493146500, 1493146560, 1493146620, 1493146680, 1493146740, 1493146800, 1493146860, 1493146920, 1493146980, 1493147040, 1493147100, 1493147160, 1493147220, 1493147280, 1493147340, 1493147400, 1493147460, 1493147520, 1493147580, 1493147640, 1493147700, 1493147760, 1493147820, 1493147880, 1493147940, 1493148000, 1493148060, 1493148120, 1493148180, 1493148240, 1493148300, 1493148360, 1493148420, 1493148480, 1493148540, 1493148600, 1493148660, 1493148720, 1493148780, 1493148840, 1493148900, 1493148960, 1493149020, 1493149080, 1493149140, 1493149200, 1493149260, 1493149320, 1493149380, 1493149440, 1493149500, 1493149560, 1493149620, 1493149680, 1493149740, 1493149800, 1493149860, 1493149920, 1493149980, 1493150040, 1493150100, 1493150160, 1493150220, 1493150280, 1493150340, 1493150400, 1493150460, 1493150520))
                )

fit.xts <- auto.arima(qxts$y)
forecast_length <- 10
fore.xts <- forecast(fit.xts, h=forecast_length)


fore.dates <- seq(as.POSIXct(qxts$date[length(qxts$date)], origin='1970-01-01'), by=qxts$date[length(qxts$date)] - qxts$date[length(qxts$date)-1], len=forecast_length)

p <- plot_ly() %>%
  add_lines(x = as.POSIXct(qxts$date, origin='1970-01-01'), y = qxts$y,
             color = I("black"), 
             name = "observed", 
             marker=list(mode='lines')) %>% 
  add_lines(x = fore.dates, y = fore.xts$mean, color = I("blue"), name = "prediction") %>%
  add_ribbons(x = fore.dates, 
              ymin = fore.xts$lower[, 2], 
              ymax = fore.xts$upper[, 2],
              color = I("gray95"), 
              name = "95% confidence") %>%
  add_ribbons(p, 
              x = fore.dates, 
              ymin = fore.xts$lower[, 1], 
              ymax = fore.xts$upper[, 1],
              color = I("gray80"), name = "80% confidence")


p

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM