R code for Winning the Internet Charts

# Packages --------------------------
library(tidyverse)
library(lubridate)

# Import --------------------------

url <- "https://github.com/the-pudding/data/raw/master/winning-the-internet/dump-2020-12-15.csv"

df <- read_csv(url) %>%
            filter(flag == F)

# Custom Theme --------------------------

theme_custom <- function () { 
  theme(axis.text.x = element_blank(),
        axis.text.y = element_text(colour="white"),
        axis.ticks.x = element_blank(),
        axis.ticks.y = element_blank(),
        panel.background = element_rect(fill = "#202124"),
        panel.grid = element_blank(),
        plot.subtitle = element_text(color = "white"),
        plot.background = element_rect(fill = "#202124"))}

# Chart 1: Newsletter Volume --------------------------

df %>% 
  count(newsletter, sort = T) %>% 
  mutate(share = n / sum(n),
         cumulative_share = cumsum(share)) %>% 
  filter(cumulative_share <= 0.5) %>% 
  ggplot(aes(reorder(newsletter, n), n, label = n)) +
  geom_text(nudge_y = 500, color = "#F72485") +
  geom_point(color = "#F72485", size = 2) +
  geom_bar(stat = "identity", width = .02, fill = "#F72485") +
  ylim(0, 8000) +
  coord_flip() +
  labs(x = "", y = "",
       subtitle = "\nWinning the Internet: top newsletters by link volume. \n(these newsletters make up 50% of all links in the dataset).") +
  theme_custom()

ggsave("fig/top_n.png", width = 10, height = 8)
Edit
Pub: 17 Mar 2021 14:15 UTC
Views: 321