xts 與 plot() 複習

在 R 視覺化時間序列資料

Arnaud Amsellem

Quantitative Trader and creator of the R Trader blog

xts 複習

  • 處理時間序列的特殊物件類別
  • eXtensible Time Series
  • xts = 時間索引 + 矩陣
  • 索引是時間物件:DatePOSIX TimetimeDatechron

第 1 章第 1 支影片投影片.003

在 R 視覺化時間序列資料

plot() 與 plot.xts()

  • plot()
  • plot.xts()
  • 當繪製的物件是 xts 時,可用 plot() 取代 plot.xts()
在 R 視覺化時間序列資料

使用 plot() 函式

第 1 章第 1 支影片投影片.010

plot(my_ts)
在 R 視覺化時間序列資料

使用 plot() 函式

第 1 章第 1 支影片投影片.013

plot(my_ts, main = "my first time series")
lines(my_ts, col = "red", lwd = 2)
在 R 視覺化時間序列資料

使用 plot() 函式

第 1 章第 1 支影片投影片.022

plot(my_ts, main = "my first time series", 
            sub = "from Sep. 2008 to Dec. 2016")
lines(my_ts, col = "red", lwd = 2)
在 R 視覺化時間序列資料

一起來練習吧!

在 R 視覺化時間序列資料

Preparing Video For Download...