Skip to content

Instantly share code, notes, and snippets.

@MichaelChirico
Created May 6, 2020 12:22
Show Gist options
  • Select an option

  • Save MichaelChirico/0b26e8300d5aa9d5ef55ef165da3bf83 to your computer and use it in GitHub Desktop.

Select an option

Save MichaelChirico/0b26e8300d5aa9d5ef55ef165da3bf83 to your computer and use it in GitHub Desktop.
@NYT_first_said + rtweet + ggrepl
library(data.table)
library(rtweet)
library(ggplot2)
library(ggrepel)
nyt_words = get_timeline(
'NYT_first_said',
n = 900,
exclude_replies = TRUE,
include_rts = FALSE
)
setDT(nyt_words)
keep = c('status_id', 'created_at', 'text', 'favorite_count', 'retweet_count', 'quote_count', 'reply_count')
nyt_words[ , setdiff(names(nyt_words), keep) := NULL]
nyt_words[ , total_engagement := favorite_count + retweet_count]
nyt_words[ , label := sprintf(
'%s\n[%s]', text, prettyNum(total_engagement, big.mark = ',')
)]
ggplot(nyt_words[!grepl('https', text, fixed = TRUE)],
aes(created_at, total_engagement,
label = fifelse(total_engagement > 1500, label, ''))) +
labs(x = '', y = 'Total Favorites and Retweets',
title = 'Crowd favorites from @NYT_first_said') +
geom_point(color = 'red') +
geom_text_repel()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment