Last active
February 4, 2018 05:29
-
-
Save herbps10/0d3396b27d4de5a843694737efc98e8a to your computer and use it in GitHub Desktop.
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