A ridgeline density plot of the ages of Olympics participants and medal winners, faceted by the medal outcome. Plotted from 1896 to 2016 Olympics (120 years). The central dot shows the mean age for that year.
#TidyTuesday
Sports
{ggridges}
Author
Aditya Dahiya
Published
August 6, 2024
This week, we’re diving into the rich history of the modern Olympic Games with a dataset from Kaggle’s RGriffin. The dataset, titled “120 years of Olympic history: athletes and results,” offers an extensive collection of data on athletes and their medal results from the Athens 1896 Olympics up to the Rio 2016 Games. This dataset, which we previously explored during TidyTuesday on July 27, 2021, includes detailed biographical data on athletes.
The data was sourced from sports-reference.com in May 2018. This site provides comprehensive data from both the Summer and Winter Games, which were held in the same year until 1992. The subsequent staggering of these events, with the Winter Games starting in 1994 and the Summer Games in 1996, is an important historical detail often overlooked in analyses. For a deeper exploration, check out the Olympics results page and the blog on sports-reference.com.
How I made this graphic?
Loading libraries & data
Code
# Data Import and Wrangling Toolslibrary(tidyverse) # All things tidy# Final plot toolslibrary(scales) # Nice Scales for ggplot2library(fontawesome) # Icons display in ggplot2library(ggtext) # Markdown text support for ggplot2library(showtext) # Display fonts in ggplot2library(colorspace) # Lighten and Darken colourslibrary(seecolor) # To print and view colourslibrary(patchwork) # Combining plots# Option 2: Read directly from GitHubolympics <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2024/2024-08-06/olympics.csv')
# Font for titlesfont_add_google("Bilbo",family ="title_font") # Font for the captionfont_add_google("Barlow Semi Condensed",family ="caption_font",regular.wt =400,bold.wt =700) # Font for plot textfont_add_google("Ubuntu Condensed",family ="body_font") showtext_auto()text_col <-"grey20"text_hil <-"grey30"bts <-80# Caption stuff for the plotsysfonts::font_add(family ="Font Awesome 6 Brands",regular = here::here("docs", "Font Awesome 6 Brands-Regular-400.otf"))github <-""github_username <-"aditya-dahiya"xtwitter <-""xtwitter_username <-"@adityadahiyaias"social_caption_1 <- glue::glue("<span style='font-family:\"Font Awesome 6 Brands\";'>{github};</span> <span style='color: {text_hil}'>{github_username} </span>")social_caption_2 <- glue::glue("<span style='font-family:\"Font Awesome 6 Brands\";'>{xtwitter};</span> <span style='color: {text_hil}'>{xtwitter_username}</span>")plot_title <-"Average Age of Olympians"plot_subtitle <-"Since the start of Modern Summer Olympics in 1896, the average age **(represented by**<br>**the dots)** of Olympics' medallists and participants has stayed around 25 years<br>**(represented by the vertical line)**. Of late, average age has been increasing slightly."str_view(plot_subtitle)plot_caption <-paste0("**Data:** _#TidyTuesday_ & RGriffin's Kaggle Dataset: ", " | **Code:** ", social_caption_1, " | **Graphics:** ", social_caption_2 )rm(github, github_username, xtwitter, xtwitter_username, social_caption_1, social_caption_2)
ggsave(filename = here::here("data_vizs", "tidy_olympics.png"),plot = g,width =400, # Best Twitter Aspect Ratio = 5:4height =500, units ="mm",bg ="white")library(magick)# Saving a thumbnail for the webpageimage_read(here::here("data_vizs", "tidy_olympics.png")) |>image_resize(geometry ="400") |>image_write(here::here("data_vizs", "thumbnails", "tidy_olympics.png"))