Skip to content

Instantly share code, notes, and snippets.

@ryanburge
Created October 31, 2018 17:00
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 ryanburge/68bfb8f0b8e16ca642310e5ed5cceed9 to your computer and use it in GitHub Desktop.
Save ryanburge/68bfb8f0b8e16ca642310e5ed5cceed9 to your computer and use it in GitHub Desktop.
RiP Post Twitter Followers 10.31.18
follow <- read_csv("D://evantwitter/update_followers.csv")
follow <- follow %>%
rename(old = Followers, new = `Followers in 2018`) %>%
mutate(n_change = new - old) %>%
mutate(pct_change = new/old) %>%
mutate(pct_change = 1 - pct_change) %>%
mutate(pct_change = -1*pct_change)
font_add_google("Abel", "font")
showtext_auto()
follow %>%
filter(pct_change > .5) %>%
ggplot(., aes(x = reorder(Username, pct_change), y = pct_change, fill = pct_change)) +
geom_col(color = "black") +
coord_flip() +
scale_y_continuous(labels = scales::percent) +
theme_minimal() +
scale_fill_gradient(low = "#33001b", high = "#ff0084") +
theme(legend.position = "none") +
theme(text=element_text(size=44, family="font")) +
labs(x = "Twitter Username", y = "Percent Change in Followers", title = "Percent Change in Followers from 2016 to 2018") +
ggsave("D://follow_change_positive.png")
follow %>%
filter(pct_change < 0) %>%
ggplot(., aes(x = reorder(Username, pct_change), y = pct_change, fill = pct_change)) +
geom_col(color = "black") +
coord_flip() +
scale_y_continuous(labels = scales::percent) +
theme_minimal() +
scale_fill_gradient(low = "#ff0084", high = "#33001b") +
theme(legend.position = "none") +
theme(text=element_text(size=44, family="font")) +
labs(x = "Twitter Username", y = "Percent Change in Followers", title = "Percent Change in Followers from 2016 to 2018") +
ggsave("D://follow_change_negative.png")
positive <- follow %>%
filter(n_change > 0) %>%
mutate(type = "Positive")
negative <- follow %>%
filter(n_change < 0) %>%
mutate(type = "Negative")
follow <- bind_rows(positive, negative)
follow %>%
ggplot(., aes(x = reorder(Username, pct_change), y = pct_change, fill = type)) +
geom_col(color = "black") +
coord_flip() +
geom_hline(yintercept = .162, linetype = "dashed") +
scale_y_continuous(labels = scales::percent) +
theme_minimal() +
scale_fill_manual(values = c("darkorchid", "firebrick3")) +
theme(legend.position = "none") +
theme(text=element_text(size=44, family="font")) +
theme(axis.text.y = element_text(size = 24)) +
labs(x = "Twitter Username", y = "Percent Change in Followers", title = "Percent Change in Followers from 2016 to 2018") +
ggsave("D://follow_change_overall.png", height = 10)
top <- follow %>%
filter(n_change > 1000000) %>%
mutate(group = "top") %>%
select(Username, n_change) %>%
add_row(Username = "Everyone Else", n_change = 3897959) %>%
mutate(n_change = n_change/1000000) %>%
mutate(n_change = round(n_change, 2)) %>%
mutate(million = "M") %>%
mutate(new = paste0(n_change, million))
top %>%
ggplot(., aes(x = reorder(Username, -n_change), y = n_change, fill = Username)) +
geom_col(color = "black") +
geom_text(aes(y = n_change + .15, label = new), position = position_dodge(width = .9), size = 16, family = "font") +
theme_minimal() +
theme(text=element_text(size=44, family="font")) +
scale_fill_npg() +
theme(legend.position = "none") +
labs(x = "Twitter Username", y = "New Followers (in Millions)", title = "Growth in Followers from 2016 to 2018") +
ggsave("D://follow_growth.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment