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
# Downloads tweets from @dog_rates and plots | |
# a histogram of dog ratings. | |
# Used to generate picture in this tweet: | |
# https://twitter.com/herbps10/status/959923100468105219 | |
library(rtweet) | |
library(tidyverse) | |
library(stringr) | |
library(cowplot) | |
library(grid) | |
library(jpeg) | |
g <- rasterGrob(readJPEG("ellie.jpg"), interpolate = TRUE) | |
tmls <- get_timelines("dog_rates", n = 3200) | |
ratings <- tmls %>% | |
filter(str_detect(text, "t.co")) %>% | |
filter(!str_detect(text, "^RT")) %>% | |
filter(!str_detect(text, "Here's a little more info on Dew")) %>% | |
mutate(rating = map(text, str_extract_all, "1[0-5]/10"), | |
rating = map(rating, `[[`, 1)) %>% | |
unnest(rating) %>% | |
count(rating) | |
ggplot(ratings, aes(x = rating, y = n)) + | |
annotation_custom(g) + | |
geom_col(fill = "white", alpha = 0.8) + | |
labs(caption = "Data: @dog_rates, photo: @KatieNicoleF", title = "577 WeRateDogs™ Ratings") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment