xts 与 plot() 函数回顾

在 R 中可视化时间序列数据

Arnaud Amsellem

Quantitative Trader and creator of the R Trader blog

xts 回顾

  • 处理时间序列的特殊对象类
  • eXtensible Time Series(可扩展时间序列)
  • xts = 时间索引 + 矩阵
  • 索引是时间对象:DatePOSIX TimetimeDatechron

ch1_vid1_slides.003.png

在 R 中可视化时间序列数据

plot() 与 plot.xts()

  • plot()
  • plot.xts()
  • 当绘制对象为 xts 时,可用 plot() 代替 plot.xts()
在 R 中可视化时间序列数据

使用 plot() 函数

ch1_vid1_slides.010.png

plot(my_ts)
在 R 中可视化时间序列数据

使用 plot() 函数

ch1_vid1_slides.013.png

plot(my_ts, main = "my first time series")
lines(my_ts, col = "red", lwd = 2)
在 R 中可视化时间序列数据

使用 plot() 函数

ch1_vid1_slides.022.png

plot(my_ts, main = "my first time series", 
            sub = "from Sep. 2008 to Dec. 2016")
lines(my_ts, col = "red", lwd = 2)
在 R 中可视化时间序列数据

Let's practice!

在 R 中可视化时间序列数据

Preparing Video For Download...