Last active
April 9, 2019 20:44
-
-
Save csgillespie/2fb595e5e4da29d758ad713f1d6ad262 to your computer and use it in GitHub Desktop.
SatRdays Twitter wars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library("rtweet") | |
library("tidyverse") # Don't judge me! | |
# Why is this not in tidyverse | |
# Can we start a petition? | |
library("lubridate") | |
# Notice the superior use of "=" over "<-" | |
get_tweets = function(q, n = 1000, include_rts = TRUE) { | |
search_tweets(q = q, n = n, | |
include_rts = include_rts, verbose = FALSE) %>% | |
filter(ymd_hms(created_at) > ymd_hms("2019-04-06 00:0:0 UTC")) | |
} | |
make_plot = function(tweets, ylab) { | |
ggplot(tweets) + | |
geom_col(aes(location, tweets)) + | |
theme_minimal() + | |
coord_flip() + | |
xlab(NULL) + ylab(ylab) | |
} | |
ncl = get_tweets("#satrdayncl", include_rts = FALSE) %>% | |
bind_rows(get_tweets("#satrdaynewcastle", include_rts = FALSE)) %>% | |
distinct(text, .keep_all = TRUE) | |
la = get_tweets("#satrdayla", include_rts = FALSE) | |
jo = get_tweets("#satRdayJoburg", include_rts = FALSE) | |
tweets = tibble(location = c("Newcastle", "LA", "SA"), | |
tweets = c(nrow(ncl), nrow(la), nrow(jo))) %>% | |
mutate(location = fct_reorder(location, .x = tweets)) | |
make_plot(tweets, "#tweets") | |
## ------ | |
fav = tibble(location = c("Newcastle", "LA", "SA"), | |
tweets = c(sum(ncl$favorite_count), | |
sum(la$favorite_count), | |
sum(jo$favorite_count))) %>% | |
mutate(location = fct_reorder(location, .x = tweets)) | |
make_plot(fav, "#fav") | |
## ------- | |
users = tibble(location = c("Newcastle", "LA", "SA"), | |
tweets = c(length(unique(ncl$user_id)), | |
length(unique(la$user_id)), | |
length(unique(jo$user_id)))) %>% | |
mutate(location = fct_reorder(location, .x = tweets)) | |
make_plot(users, "#users") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment