Skip to content

Instantly share code, notes, and snippets.

@herbps10
Created February 25, 2018 23:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save herbps10/1908ebecba9ccec4a5e90d0c8970ec8d to your computer and use it in GitHub Desktop.
Save herbps10/1908ebecba9ccec4a5e90d0c8970ec8d to your computer and use it in GitHub Desktop.
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