zoo 与 ggplot2
与数据框类似,zoo 对象也可以使用 ggplot2 包中的函数进行可视化。虽然本课程不会深入讲解 ggplot2 的绘图与函数,但回顾其语法仍然有助于掌握比单用 autoplot() 更高级的绘图技巧。
在本练习中,您将一起使用 zoo 和 ggplot2。您会取用上一个练习中的 card_prices 时间序列,生成一幅 ggplot 图,并添加合适的坐标轴标签、标题和主题!
zoo、ggplot2 和 card_prices 已可直接使用。
本练习是课程的一部分
R 中的时间序列数据处理
练习说明
在对
aes()的调用中,为 x 轴和 y 轴填入合适的映射。将时间序列绘制为折线,并将颜色设置为红色。
使用
ggplot2的浅色主题。加入坐标轴标签和标题:x 轴为
"Index",y 轴为"Price (EUR)",标题为"Daily Card Prices for Trading Card Game"。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Enter the x and y axis mapping aesthetics
ggplot(card_prices, aes(x = ___, y = ___)) +
scale_y_continuous() +
# Plot the data with a red-colored line
___ +
# Use the light theme
___ +
# Enter the appropriate axis labels and title
labs(
___
)