Seasonal plots
Along with time plots, there are other useful ways of plotting data to emphasize seasonal patterns and show changes in these patterns over time.
- A seasonal plot is similar to a time plot except that the data are plotted against the individual “seasons” in which the data were observed. You can create one using the
ggseasonplot()
function the same way you do withautoplot()
. - An interesting variant of a season plot uses polar coordinates, where the time axis is circular rather than horizontal; to make one, simply add a
polar
argument and set it toTRUE
. - A subseries plot comprises mini time plots for each season. Here, the mean for each season is shown as a blue horizontal line.
One way of splitting a time series is by using the window()
function, which extracts a subset from the object x
observed between the times start
and end
.
> window(x, start = NULL, end = NULL)
In this exercise, you will load the fpp2
package and use two of its datasets:
a10
contains monthly sales volumes for anti-diabetic drugs in Australia. In the plots, can you see which month has the highest sales volume each year? What is unusual about the results in March and April 2008?ausbeer
which contains quarterly beer production for Australia. What is happening to the beer production in Quarter 4?
These examples will help you to visualize these plots and understand how they can be useful.
This is a part of the course
“Forecasting in R”
Exercise instructions
- Use
library()
to load thefpp2
package. - Use
autoplot()
andggseasonplot()
to produce plots of thea10
data. - Use the
ggseasonplot()
function and itspolar
argument to produce a polar coordinate plot for thea10
data. - Use the
window()
function to consider only theausbeer
data starting from 1992. - Finally, use
autoplot()
andggsubseriesplot()
to produce plots of thebeer
series.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Load the fpp2 package
___
# Create plots of the a10 data
___
___
# Produce a polar coordinate season plot for the a10 data
ggseasonplot(___, polar = ___)
# Restrict the ausbeer data to start in 1992
beer <- ___(___, ___)
# Make plots of the beer data
___
___