R: tidytext: sentiment wordcloud
Revision as of 09:42, 3 December 2019 by Onnowpurbo (talk | contribs) (Created page with "# Ref: https://github.com/dgrtwo/tidy-text-mining/blob/master/02-sentiment-analysis.Rmd library(RColorBrewer) library(wordcloud) tidy_books %>% anti_join(stop_words) %>...")
library(RColorBrewer) library(wordcloud) tidy_books %>% anti_join(stop_words) %>% count(word) %>% with(wordcloud(word, n, max.words = 100)) # In other functions, such as `comparison.cloud()`, you may need to turn the data frame # into a matrix with reshape2's `acast()`. Let's do the sentiment analysis # to tag positive and negative words using an inner join, then find # the most common positive and negative words. # Until the step where we need to send the data to `comparison.cloud()`, # this can all be done with joins, piping, and dplyr because our data is in tidy format. library(reshape2) tidy_books %>% inner_join(get_sentiments("bing")) %>% count(word, sentiment, sort = TRUE) %>% acast(word ~ sentiment, value.var = "n", fill = 0) %>% comparison.cloud(colors = c("gray20", "gray80"), max.words = 100)