Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
common squirrel
library(rtweet)
library(tidyverse)
library(stringr)
library(cowplot)
library(grid)
library(jpeg)
library(lubridate)
library(tidytext)
g <- rasterGrob(readJPEG("common_squirrel.jpg"), interpolate = TRUE)
tmls <- get_timelines("common_squirrel", n = 22000)
tmls_filtered <- tmls %>%
select(text) %>%
mutate(text = str_replace(text, "!", "")) %>%
filter(!str_detect(text, "^@")) %>%
filter(!str_detect(text, "https://t.co/[a-zA-Z0-9]+")) %>%
filter(str_detect(text, "^(\\w+)(\\s\\1)*$"))
word_counts <- tmls_filtered %>%
unnest_tokens(word, text) %>%
count(word)
ggplot(word_counts, aes(x = reorder(word, -n), y = n)) +
annotation_custom(g) +
geom_col(fill = "white", alpha = 0.8) +
labs(caption = "Data & photo: @common_squirrel", title = "3,105 @common_squirrel activities", x = "activity", y = "n") +
theme(axis.text.x = element_text(size = 10, angle = 0, hjust = 0.5))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment