Created
August 2, 2018 04:01
-
-
Save neilfws/0c42237c4e1a96531d5ada2621f7ad07 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
# function to make the cloud | |
# assumes rtweet authentication configured as per documentation | |
make_tweetcloud <- function(user = "neilfws", tweets = 100) { | |
require(tidyverse) | |
require(tidytext) | |
require(rtweet) | |
require(wordcloud) | |
get_timeline(user, n = tweets, full_text = TRUE) %>% | |
mutate(text = gsub("@[A-Za-z0-9_]+", "", text)) %>% | |
unnest_tokens(word, text) %>% | |
anti_join(stop_words) %>% | |
count(word) %>% | |
filter(!word %in% c("https", "t.co", "amp"), | |
!grepl("^\\d+$", word)) %>% | |
with(wordcloud(word, | |
n, | |
max.words = 100, | |
min.freq = 3, | |
colors = brewer.pal(8, "Dark2"))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The first
mutate
is to remove user names; there is probably a better way.