Last active
November 1, 2021 17:15
-
-
Save leeolney3/c0f87667a15db3dfc8c292fb88adc8ab to your computer and use it in GitHub Desktop.
TidyTuesday 2021/44
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(ggtext) | |
library(lubridate) | |
library(ggmosaic) | |
ultra_rankings <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-10-26/ultra_rankings.csv') | |
race <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-10-26/race.csv') | |
df = ultra_rankings %>% left_join(race, by="race_year_id") | |
df %>% mutate(year= year(date), | |
gender=recode(gender, "M"="Man", "W"="Woman")) %>% | |
filter(!is.na(gender)) %>% | |
filter(year<=2020) %>% | |
ggplot() + | |
geom_mosaic(aes(x=product(gender, year), fill=gender)) + | |
geom_text(data = layer_data(last_plot(), 1) %>% filter(.wt > 0), | |
aes(x = (xmin + xmax) / 2, | |
y = (ymin + ymax) / 2, | |
label = .wt), size=3, color="white") + | |
coord_cartesian(expand=F, clip="off") + | |
scale_fill_manual(values=c("#5B3A90","#115B51")) + | |
theme_minimal() + | |
theme(legend.position = "none", | |
panel.grid=element_blank(), | |
axis.title=element_blank(), | |
axis.text.x=element_text(size=8, color="#343a40"), | |
axis.text.y=element_text(size=9, color="#343a40"), | |
plot.title.position="plot", | |
plot.subtitle=element_markdown(size=7.5, lineheight = 1.3, margin=margin(b=10)), | |
plot.title=element_markdown(family="Roboto"), | |
plot.margin = unit(c(.5, 1.25, .5, .75), "cm"), | |
plot.caption=element_text(size=6.5, hjust=0, margin=margin(t=10)), | |
plot.caption.position = "plot" | |
) + | |
labs(y="Gender", x="Year", | |
subtitle="Breakdown of ultra running participants by gender and by year, from Jan 14, 2012 to Dec 26, 2021, shown as a mosiac plot. The widths of<br>each rectangle are porportional to the number of participants in that year and the heights are porportional to the number of participants by<br>gender. Numbers represent the counts of participants within each category. The highest number of participants (n= 24,564) was in 2019, and<br>lowest (n= 6,909) was in 2020. The largest proportion of women participants (16.8%) was in 2020, and smallest proportion (13.6%) in 2013.", | |
title="<span style = 'color:#115B51;'>**Women**</span> and <span style = 'color:#5B3A90;'>**Man**</span> Ultra Running Participants", | |
caption="#TidyTuesday week 44 | Data from from Benjamin Nowak by way of International Trail Running Association (ITRA)" | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment