plot(USAccDeaths)
fit <- stl(USAccDeaths, s.window = "periodic")
lines(trendcycle(fit), col = "red")
library(ggplot2)
autoplot(
cbind(
Data = USAccDeaths,
Seasonal = seasonal(fit),
Trend = trendcycle(fit),
Remainder = remainder(fit)
),
facets = TRUE
) +
labs(x = "Year", y = "")
Run the code above in your browser using DataLab