1. Learn
  2. /
  3. 课程
  4. /
  5. 使用 tidyr 重塑数据

Connected

道练习

各大洲的奥运奖牌数

您想比较各大洲运动员在冬奥会和夏奥会上的长期表现。数据集 medal_df 提供了自 1928 年以来各大洲每位参赛者平均获得的奖牌数。您需要补全这些数据,为某些大洲未获奖牌的年份引入 0 值。

Olympic flag

ggplot2 包已为您预加载。

说明

100 XP
  • 补全过程数据,确保每个 continent 在每届奥运会上都有 medals_per_participant 数值。将缺失值填充为 0。
  • 使用 nesting() 将 season 和 year 组合嵌套,因为夏奥会与冬奥会并不在同一年举行。
  • 使用 ggplot() 绘制折线图:以 year 为横轴、medals_per_participant 为纵轴,并按 continent 着色。