Skip to content

Instantly share code, notes, and snippets.

@sharlagelfand
Created July 2, 2020 15:21
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 sharlagelfand/9427ebe3d0892d08a0c52f02ef87450e to your computer and use it in GitHub Desktop.
Save sharlagelfand/9427ebe3d0892d08a0c52f02ef87450e to your computer and use it in GitHub Desktop.
library(rtweet)
library(dplyr)
library(tidytext)
library(stringr)
library(ggplot2)
library(ggwordcloud)
dc <- search_tweets(
"datacamp",
n = 1000, include_rts = FALSE
)
dc_words <- dc %>%
filter(
screen_name != "DataCamp",
created_at >= "2020-07-01"
) %>%
select(text) %>%
unnest_tokens(word, text, token = "tweets", drop = FALSE) %>%
filter(!str_starts(word, "@")) %>%
anti_join(stop_words, by = "word")
dc_words %>%
left_join(get_sentiments("afinn"), by = "word") %>%
filter(value <= 0) %>%
count(word, value) %>%
filter(n > 1) %>%
ggplot() +
geom_text_wordcloud(aes(label = word, size = n)) +
scale_size_area(max_size = 14) +
theme_minimal()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment