forked from jbkunst/highcharter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseasonal.R
30 lines (23 loc) · 913 Bytes
/
seasonal.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
library("seasonal")
object <- seas(AirPassengers,
regression.aictest = c("td", "easter"),
outlier.critical = 3)
plot(object)
#' @importFrom seasonal original final trend outlier
hchart.seas <- function(object, outliers = TRUE, trend = FALSE, ...) {
hc <- highchart() %>%
hc_add_serie_ts(original(object), name = "original", zIndex = 3, id = "original") %>%
hc_add_serie_ts(final(object), name = "adjusted", zIndex = 2, id = "adjusted")
if (trend) {
hc <- hc %>% hc_add_serie_ts(trend(object), name = "trend", zIndex = 1)
}
if (outliers) {
ol.ts <- outlier(object)
ixd.nna <- !is.na(ol.ts)
text <- as.character(ol.ts)[!is.na(ol.ts)]
dates <- zoo::as.Date(time(ol.ts))[!is.na(ol.ts)]
hc <- hc %>% hc_add_series_flags(dates, text, text,
name = "outiliers", id = "adjusted")
}
hc
}