Skip to content

Instantly share code, notes, and snippets.

@mine-cetinkaya-rundel
Created April 13, 2020 08:13
Show Gist options
  • Save mine-cetinkaya-rundel/368682ce9db629961c07912c7ed1a7bc to your computer and use it in GitHub Desktop.
Save mine-cetinkaya-rundel/368682ce9db629961c07912c7ed1a7bc to your computer and use it in GitHub Desktop.
NYT First Said counts, labelling highest
library(rtweet)
library(tidyverse)
library(glue)
rt <- get_timeline(
user = "@NYT_first_said",
n = 18000
)
rt <- rt %>%
mutate(
week = round_time(created_at, "weeks"),
day = round_time(created_at, "days")
)
highest_day <- rt %>%
count(day, sort = TRUE) %>%
top_n(1) %>%
pull(day)
bizarre_words <- rt %>%
filter(day == highest_day) %>%
pull(text) %>%
glue_collapse(sep = ", ")
# there has to be a better way then manually adding line breaks
bw <- structure("bioanthropological, taphonomic, fornici, talentism,oenocentric, \nskateways, seafacing, mchicha, chaza, ufuta, mkate, mishkaki, \nhitokuchigashi, chamoe, vchill, kvavili, kviteli, ojaxuri, gandzili, \nekala, bewk, semispheres, salmiana, sgàilean, retarch, beefcheeks, \nhellasmacked, acousticophobic, epigrammed, demantoids, \nastrocartographer, goosings, hamaka, nonejected, gumtrees, \nreganmian, overincarcerates, vibratode, subfile", class = c("glue",
"character"))
rt_counts <- rt %>%
group_by(day) %>%
mutate(
words = glue_collapse(text, sep = ", "),
n = n()
) %>%
select(day, words, n) %>%
distinct(day, .keep_all = TRUE) %>%
mutate(words = if_else(day == highest_day, bw, words))
ggplot(rt_counts, aes(x = day, y = n)) +
geom_line(color = "darkgray", size = 0.5) +
theme_minimal() +
theme(plot.title = ggplot2::element_text(face = "bold")) +
labs(
x = NULL, y = NULL,
title = "Frequency of tweets from @NYT_first_said",
subtitle = "Tweet counts aggregated using daily intervals",
caption = "\nData: Twitter's REST API via rtweet | Graph: @minebocek"
) +
ggrepel::geom_label_repel(
data = rt_counts %>% filter(day == highest_day), aes(label = words),
hjust = 1.5, vjust = 1
) +
ggrepel::geom_text_repel(
data = rt_counts %>% filter(day == highest_day), aes(label = as.character(day)),
vjust = 1
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment