@@ -57,6 +57,27 @@ fig <- fig %>% layout(xaxis = list(title = 'Displacement (cu.in.)'),
57
57
fig
58
58
```
59
59
60
+ ### Plotting Forecast Objects
61
+
62
+ ``` {r}
63
+ library(plotly)
64
+ library(forecast)
65
+
66
+ fit <- ets(USAccDeaths)
67
+ fore <- forecast(fit, h = 48, level = c(80, 95))
68
+
69
+ fig <- plot_ly()
70
+ fig <- fig %>% add_lines(x = time(USAccDeaths), y = USAccDeaths,
71
+ color = I("black"), name = "observed")
72
+ fig <- fig %>% add_ribbons(x = time(fore$mean), ymin = fore$lower[, 2], ymax = fore$upper[, 2],
73
+ color = I("gray95"), name = "95% confidence")
74
+ fig <- fig %>% add_ribbons(x = time(fore$mean), ymin = fore$lower[, 1], ymax = fore$upper[, 1],
75
+ color = I("gray80"), name = "80% confidence")
76
+ fig <- fig %>% add_lines(x = time(fore$mean), y = fore$mean, color = I("blue"), name = "prediction")
77
+
78
+ fig
79
+ ```
80
+
60
81
### Loess Smoother with Uncertainty Bounds
61
82
62
83
``` {r}
@@ -83,26 +104,7 @@ fig <- fig %>% layout(xaxis = list(title = 'Displacement (cu.in.)'),
83
104
fig
84
105
```
85
106
86
- ### Plotting Forecast Objects
87
-
88
- ``` {r}
89
- library(plotly)
90
- library(forecast)
91
-
92
- fit <- ets(USAccDeaths)
93
- fore <- forecast(fit, h = 48, level = c(80, 95))
94
-
95
- fig <- plot_ly()
96
- fig <- fig %>% add_lines(x = time(USAccDeaths), y = USAccDeaths,
97
- color = I("black"), name = "observed")
98
- fig <- fig %>% add_ribbons(x = time(fore$mean), ymin = fore$lower[, 2], ymax = fore$upper[, 2],
99
-
67BD
color = I("gray95"), name = "95% confidence")
100
- fig <- fig %>% add_ribbons(x = time(fore$mean), ymin = fore$lower[, 1], ymax = fore$upper[, 1],
101
- color = I("gray80"), name = "80% confidence")
102
- fig <- fig %>% add_lines(x = time(fore$mean), y = fore$mean, color = I("blue"), name = "prediction")
103
107
104
- fig
105
- ```
106
108
107
109
#Reference
108
110
0 commit comments