Created
February 25, 2018 23:46
-
-
Save herbps10/1908ebecba9ccec4a5e90d0c8970ec8d to your computer and use it in GitHub Desktop.
common squirrel
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) | |
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