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(
___
)