Skip to content

Instantly share code, notes, and snippets.

@andrewheiss
Created July 21, 2022 20:47
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewheiss/b85c72e2cadb496fed0b8715ef5cacf5 to your computer and use it in GitHub Desktop.
Save andrewheiss/b85c72e2cadb496fed0b8715ef5cacf5 to your computer and use it in GitHub Desktop.
library(tidyverse)
library(gapminder)
library(geomtextpath)
library(ggborderline)
library(MetBrewer)

countries <- c("Norway", "Iraq", "Rwanda", "Afghanistan")
# Assistant font from Google
# https://fonts.google.com/specimen/Assistant
gapminder %>% 
  filter(country %in% countries) %>% 
  mutate(country = factor(country, levels = countries, ordered = TRUE)) %>% 
  ggplot(aes(x = year, y = lifeExp, color = country)) +
  geom_line(data = gapminder, aes(group = country, color = NULL), size = 0.1, color = "grey70") +
  geom_borderline(size = 1, bordersize = 1) +
  geom_labelline(aes(label = country, hjust = country, fill = country),
                linecolor = NA, size = 4, textcolour = "white",
                family = "Assistant SemiBold") +
  scale_hjust_discrete(range = c(0.05, 0.055)) +
  scale_color_manual(values = met.brewer("Egypt", 4)) +
  scale_fill_manual(values = met.brewer("Egypt", 4)) +
  guides(color = "none", fill = "none") +
  labs(x = NULL, y = "Life expectancy", 
       title = "Life expectancy over time",
       subtitle = "Gaps around the intersections!!",
       caption = "Source: The Gapminder Project") +
  theme_minimal(base_family = "Assistant") +
  theme(panel.grid.minor = element_blank(),
        plot.title = element_text(family = "Assistant", face = "bold", size = rel(1.5)),
        plot.caption = element_text(family = "Assistant ExtraLight", size = rel(0.7), hjust = 0,
                                    margin = margin(t = 15)))

Created on 2022-07-21 by the reprex package (v2.0.1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment