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.
The ggplot2
package has been pre-loaded for you.
This exercise is part of the course
Reshaping Data with tidyr
Exercise instructions
- Complete the dataset so that each
continent
has amedals_per_participant
value at each Olympic event. Missing values should be filled with zeros. - Nest the
season
andyear
variables using thenesting()
function, since the summer and winter Olympics don't occur in the same years. - Use
ggplot()
to create a line plot with themedals_per_participant
peryear
, color the plot bycontinent
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
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 ~ .)