Instantly share code, notes, and snippets.

Embed
What would you like to do?
Creating a comparison cloud in R with wordcloud
library(gutenbergr)
library(tidytext)
library(dplyr)
library(wordcloud)
dracula<-gutenberg_download(345)
dracula$gutenberg_id<-NULL
dracula<-dracula%>%
unnest_tokens(word, text)
bing<-get_sentiments('bing')
dracula<-inner_join(dracula, bing)
words<-dracula%>%
group_by(word)%>%
summarize(count=n(), sentiment=first(sentiment))%>%
arrange(count)
# A normal wordcloud plot
wordcloud(words$word, words$count, max.words=150)
# Reshaping our data to a matrix with reshape2
library(reshape2)
matrix<-acast(words, word~sentiment, value.var='count', fill=0)
# The comparison cloud
comparison.cloud(matrix, colors=c('black', 'orange'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment