Difference between revisions of "R: tidytext: sentiment wordcloud"

From OnnoWiki
Jump to navigation Jump to search
(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) %>...")
 
 
Line 1: Line 1:
# Ref: https://github.com/dgrtwo/tidy-text-mining/blob/master/02-sentiment-analysis.Rmd
+
# Ref: https://github.com/dgrtwo/tidy-text-mining/blob/master/02-sentiment-analysis.Rmd
  
 
  library(RColorBrewer)
 
  library(RColorBrewer)

Latest revision as of 09:50, 3 December 2019

# Ref: https://github.com/dgrtwo/tidy-text-mining/blob/master/02-sentiment-analysis.Rmd
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)


Referensi

Pranala Menarik