視覺化波士頓的冬季
你在上一章發現,波士頓在冬季延誤或取消的航班比例高得多。看來氣溫是個重要因素。也許氣溫越低,就與更高比例的航班延誤或取消有關?
在這個練習中,你會透過隨時間繪製氣溫趨勢,產生波士頓冬季的視覺化總覽,來檢視這個假設是否合理。
本練習屬於課程
個案研究:在 R 中分析城市時間序列資料
練習說明
- 在繪圖前,使用
periodicity()檢查資料的週期性與時間範圍。先了解週期性有助於你解讀資料,接下來也會派上用場。 - 使用
plot.xts()繪製整段資料期間的波士頓平均氣溫(temps_xts$mean)。 - 再繪製一張圖,範圍限定為 2010 年 11 月到 2011 年 4 月(含首尾)。
- 使用
plot.zoo()複製上一張圖,但同時納入資料中的其他欄位(此例為min與max氣溫)。將plot.type指定為"single",讓三條折線畫在同一個面板中。不要更動預先寫好的lty參數。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Identify the periodicity of temps_xts
# Generate a plot of mean Boston temperature for the duration of your data
plot.xts(___)
# Generate a plot of mean Boston temperature from November 2010 through April 2011
plot.xts(___["___/___"])
# Use plot.zoo to generate a single plot showing mean, max, and min temperatures during the same period
plot.zoo(___["___/___"], plot.type = "___", lty = lty)