Description Usage Arguments Details Value See Also Examples
Creates a four-facet plot of seasonal decomposition showing observed, trend, seasonal and random components
1 2 3 4 |
data |
dataset to use for plot. |
mapping |
List of aesthetic mappings. Must include x and y, and optionally can include colour/color |
frequency |
frequency of the period of the time series eg 12 = monthly |
method |
function to use for performing the seasonal decomposition. stl
and decompose are functions in the |
start |
starting time for the data; only needed if |
s.window |
parameter to pass to |
type |
parameter to pass to |
index.ref |
if not NULL, a vector of integers indicating which elements of the beginning of each series to use as a reference point for converting to an index. If NULL, no conversion takes place and the data are presented on the original scale. |
index.basis |
if index.ref is not NULL, the basis point for converting to an index, most commonly 100 or 1000. See examples. |
facet.titles |
a vector in the order of |
This function takes a data frame and performs seasonal decomposition on the variable mapped to the y aesthetic, grouped by the variable (if any) mapped to the colour or color aesthetic. This allows the user to perform the equivalent of plot(stats::decompose(x)) but in the ggplot2 environment for themes, polishing etc; and to overlay decompositions on the same graphic; and with the X13-SEATS-ARIMA seasonal decomposition (so far only with default settings).
The "seasonal" component can be either multiplicative (in which case it will in a small range of values around one) or additive (in which case it will be on the scale of the original data), depending on the settings.
an object of class ggplot with four facets
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 31 32 33 34 35 36 37 38 39 | # sample time series data in data frame
ap_df <- tsdf(AirPassengers)
ggsdc(ap_df, aes(x = x, y = y), method = "decompose") +
geom_line()
ggsdc(ap_df, aes(x = x, y = y), method = "decompose",
type = "multiplicative") +
geom_line(colour = "blue", size = 2) +
theme_light(8)
ggsdc(ap_df, aes(x = x, y = y), method = "stl", s.window = 7) +
labs(x = "", y = "Air passenger numbers") +
geom_point()
## Not run:
ggsdc(ldeaths_df, aes(x = YearMon, y = deaths, colour = sex), method = "seas") +
geom_line()
serv <- subset(nzbop, Account == "Current account" &
Category %in% c("Services; Exports total", "Services; Imports total"))
ggsdc(serv, aes(x = TimePeriod, y = Value, colour = Category),
method = "seas", start = c(1971, 2), frequency = 4) +
geom_line()
## End(Not run)
ggsdc(ldeaths_df, aes(x = YearMon, y = deaths, colour = sex), s.window = 7,
index.ref = 1:12, index.basis = 1000) +
geom_line() +
ylab("Lung deaths index (average month in 1974 = 1000)")
bop <- subset(nzbop, Account == "Current account" & !Balance)
ggsdc(bop, aes(x = TimePeriod, y = Value, colour = Category), frequency = 4,
method = "decomp", type = "multiplicative") +
geom_line()
ggsdc(bop, aes(x = TimePeriod, y = Value, colour = Category), frequency = 4, s.window = 7) +
geom_line()
|
Loading required package: ggplot2
Calculating frequency of 12 from the data.
Warning message:
Removed 6 rows containing missing values (geom_path).
Calculating frequency of 12 from the data.
Warning message:
Removed 6 rows containing missing values (geom_path).
Calculating frequency of 12 from the data.
Calculating starting date of 1974 from the data.
Calculating frequency of 12 from the data.
Calculating starting date of 1974 from the data.
Calculating frequency of 12 from the data.
Calculating frequency of 12 from the data.
Calculating frequency of 12 from the data.
Warning message:
Removed 20 rows containing missing values (geom_path).
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.