Time series plotting
In this section, we will cover plotting time series objects, along with plotting some diagnostics such as decomposition. These plots include time series plots themselves, autocorrelation function (ACF) plots, and partial autocorrelation function (PACF) plots. We will start by using the AirPassengers dataset, which we will read in via the readxl
package:
# Read the airpassengers.xlsx file in and convert to a ts object starting at 1949 ap_ts <- read_xlsx("./Chapter 10/airpassengers.xlsx")Â Â |> Â Â ts(start = 1949, frequency = 12) # Plot the ts object plot(ap_ts)
This produces the following chart:
Figure 10.2 – Visualizing the AirPassengers time series dataset
From here, it is easy to see that the data has a trend and a seasonal cycle component. This observation will lead us to our next visual. We will decompose the data into its parts and visualize the decomposition. The decomposition of the...