decompose a time series using the stl model and plot the decokmposition plot using autoplot in r

Here's how to decompose a time series in R using the stl model and plot the decomposition plot using autoplot:

main.r
#load required packages
library(forecast)

#load data 
data <- AirPassengers

#decompose time series using STL
decompose <- stl(data, s.window="periodic")

#plot decomposition using autoplot
autoplot(decompose)
211 chars
12 lines

This will give you a plot that shows the time series, the trend, seasonal component, and the remainder component.

gistlibby LogSnag