各大洲的奥运奖牌数
您想比较各大洲运动员在冬奥会和夏奥会上的长期表现。数据集 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 ~ .)