季节性图
除了时间图外,还有一些有用的绘图方式可以突出季节性模式,并展示这些模式随时间的变化。
- 季节性图 与时间图类似,但数据是按观测发生的各个"季节"作图。您可以像使用
autoplot()一样,使用ggseasonplot()函数来创建。 - 季节图的一个有趣变体是使用极坐标,此时时间轴是圆形而非水平的;只需添加
polar参数并将其设为TRUE即可。 - 子序列图 由每个季节的小型时间图组成。这里,每个季节的均值会用蓝色水平线表示。
拆分时间序列的一种方法是使用 window() 函数,它会从对象 x 中提取介于 start 和 end 时间之间的子集。
> window(x, start = NULL, end = NULL)
在本练习中,您将加载 fpp2 包并使用其中的两个数据集:
a10包含澳大利亚抗糖尿病药物的月度销量。在图中,您能看出每年哪个月份的销量最高吗?2008 年 3 月和 4 月的结果有什么异常之处?ausbeer包含澳大利亚的季度啤酒产量。第 4 季度的啤酒产量发生了什么变化?
这些示例将帮助您直观理解这些图形,并了解它们的用途。
本练习是课程的一部分
R 中的预测
练习说明
- 使用
library()加载fpp2包。 - 使用
autoplot()和ggseasonplot()绘制a10数据的图。 - 使用
ggseasonplot()函数及其polar参数,为a10数据生成极坐标图。 - 使用
window()函数,只保留从 1992 年"开始"的ausbeer数据。 - 最后,使用
autoplot()和ggsubseriesplot()绘制beer序列的图形。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# 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
___
___