开始使用免费开始使用

各大洲的奥运奖牌数

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

Olympic flag

ggplot2 包已为您预加载。

本练习是课程的一部分

使用 tidyr 重塑数据

查看课程

练习说明

  • 补全过程数据,确保每个 continent 在每届奥运会上都有 medals_per_participant 数值。将缺失值填充为 0。
  • 使用 nesting()seasonyear 组合嵌套,因为夏奥会与冬奥会并不在同一年举行。
  • 使用 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 ~ .)
编辑并运行代码