Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# 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")))
}
@neilfws
Copy link
Author

neilfws commented Aug 2, 2018

The first mutate is to remove user names; there is probably a better way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment