Categories
R

Trump acceptance speech wordcloud via R

Used some simple R to create this

Wordcloud of the Trump acceptance speech at the Republican Convention.
Wordcloud of the Trump acceptance speech at the Republican Convention.

Not alot of insight to be had. Possibly because of the teleprompter he used.

 

Code:

setwd("~/cloud/R/")
aFile = readLines("trumpacceptance.txt")
library(tm)
library("SnowballC")
myCorpus = Corpus(VectorSource(aFile))
myCorpus = tm_map(myCorpus,  content_transformer(tolower))
myCorpus = tm_map(myCorpus, removePunctuation)
myCorpus = tm_map(myCorpus, removeNumbers)
myCorpus = tm_map(myCorpus, removeWords, stopwords("english"))
myCorpus <- tm_map(myCorpus, PlainTextDocument)
myDTM = TermDocumentMatrix(myCorpus, control = list(minWordLength = 1))

m = as.matrix(myDTM)
v = sort(rowSums(m), decreasing = TRUE)

library(wordcloud)
set.seed(4333)
d <- data.frame(word = names(v),freq=v)
wordcloud(words = d$word, freq = d$freq, min.freq = 1,  max.words=200, random.order=FALSE, rot.per=0.35,  colors=brewer.pal(8, "Dark2"))