各洲奧運獎牌數/參賽者
你想比較各洲選手在歷屆奧運(含冬季與夏季)中的表現。你拿到一個資料集 medal_df,內容是自 1928 年起,各洲「每位參賽者平均獲得的獎牌數」。你將把資料補齊,在某洲某年沒有獎牌的情況下,以 0 表示。

已為你預先載入 ggplot2 套件。
本練習屬於課程
使用 tidyr 重塑資料
練習說明
- 補齊資料集,讓每個
continent在每一屆奧運都有medals_per_participant值。遺漏值請以 0 補上。 - 使用
nesting()函式巢狀season和year變數,因為夏季奧運與冬季奧運並非同一年舉行。 - 使用
ggplot()繪製折線圖,將year對應到medals_per_participant,並以continent分色。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
medal_df %>%
# Give each continent an observation at each Olympic event
complete(
___,
___,
fill = ___(___ = ___)
) %>%
# Plot the medals_per_participant over time, colored by continent
ggplot(___) +
___ +
facet_grid(season ~ .)