Aan de slagGa gratis aan de slag

Olympic medals per continent

You want to compare Olympic performance of athletes per continent over time, both on the winter and summer Olympics. You've been given a dataset medal_df with the average number of medals won per participant of each continent since 1928. You'll complete this data to introduce zero values for years where a continent did not win any medals.

Olympic flag

The ggplot2 package has been pre-loaded for you.

Deze oefening maakt deel uit van de cursus

Reshaping Data with tidyr

Cursus bekijken

Oefeninstructies

  • Complete the dataset so that each continent has a medals_per_participant value at each Olympic event. Missing values should be filled with zeros.
  • Nest the season and year variables using the nesting() function, since the summer and winter Olympics don't occur in the same years.
  • Use ggplot() to create a line plot with the medals_per_participant per year, color the plot by continent.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

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 ~ .)
Code bewerken en uitvoeren