Skip to content

Instantly share code, notes, and snippets.

@andrewheiss
Created July 21, 2022 20:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewheiss/542e2882f21f155d52bdd7fecf24b487 to your computer and use it in GitHub Desktop.
Save andrewheiss/542e2882f21f155d52bdd7fecf24b487 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_borderline(bordersize = 1) +
  geom_labelline(aes(label = country, hjust = country),
                linecolor = NA, size = 4,
                family = "Assistant SemiBold") +
  scale_hjust_discrete(range = c(0.05, 0.055)) +
  scale_color_manual(values = met.brewer("Egypt", 4)) +
  guides(color = "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