Skip to content

Instantly share code, notes, and snippets.

@tukachev
Created September 4, 2023 10:55
Show Gist options
  • Save tukachev/ff856099acff80eb8a683bb71979fdf8 to your computer and use it in GitHub Desktop.
Save tukachev/ff856099acff80eb8a683bb71979fdf8 to your computer and use it in GitHub Desktop.
library(tidyverse)
library(ggdark)
astronauts <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-07-14/astronauts.csv')
astronauts <- astronauts %>%
mutate(age_at_selection = year_of_selection - year_of_birth,
age_at_mission = year_of_mission - year_of_birth)
astronauts %>%
group_by(name) %>%
mutate(first_mission_age = min(age_at_mission),
mission_number = row_number()) %>%
select(name, year_of_mission, first_mission_age, mission_number) %>%
filter(mission_number == 1) %>%
ggplot(aes(x = year_of_mission, y = first_mission_age)) +
geom_jitter(size = 3.5, colour = "deepskyblue3", alpha = 0.35) +
geom_smooth(colour = "firebrick", alpha = 0.5) +
scale_x_continuous(breaks = seq(1960,2020,5)) +
scale_y_continuous(breaks = seq(20,60,5)) +
expand_limits(y = c(20,61)) +
labs(title = "Astronauts getting progressively older",
subtitle = "Age of each astronaut at the time of their first mission",
x = "Year of mission",
y = "Age of Astronaut during first mission") +
dark_theme_light()
ggsave(filename = "age_during_first_mission.png",
scale = 0.8, height = 5, width = 7, dpi = 600)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment