install.packages(c("tm", "SnowballC", "wordcloud", "RColorBrewer", "RCurl", "XML"))
## Installing packages into '/cloud/lib/x86_64-pc-linux-gnu-library/4.3'
## (as 'lib' is unspecified)
library("tm")
## Loading required package: NLP
library("SnowballC")
library("wordcloud")
## Loading required package: RColorBrewer
library("RColorBrewer")
library("RCurl")
library("RCurl")
library("XML")

source('http://www.sthda.com/upload/rquery_wordcloud.r')
filePath <- "http://www.sthda.com/sthda/RDoc/example-files/martin-luther-king-i-have-a-dream-speech.txt"
res<-rquery.wordcloud(filePath, type ="file", lang = "english")
## Warning in tm_map.SimpleCorpus(docs,
## content_transformer(tolower)): transformation drops documents
## Warning in tm_map.SimpleCorpus(docs, removeNumbers):
## transformation drops documents
## Warning in tm_map.SimpleCorpus(docs, removeWords,
## stopwords(lang)): transformation drops documents
## Warning in tm_map.SimpleCorpus(docs, removePunctuation):
## transformation drops documents
## Warning in tm_map.SimpleCorpus(docs, stripWhitespace):
## transformation drops documents

res<-rquery.wordcloud(filePath, type ="file", lang = "english",
                      min.freq = 1,  max.words = 200)
## Warning in tm_map.SimpleCorpus(docs,
## content_transformer(tolower)): transformation drops documents
## Warning in tm_map.SimpleCorpus(docs, removeNumbers):
## transformation drops documents
## Warning in tm_map.SimpleCorpus(docs, removeWords,
## stopwords(lang)): transformation drops documents
## Warning in tm_map.SimpleCorpus(docs, removePunctuation):
## transformation drops documents
## Warning in tm_map.SimpleCorpus(docs, stripWhitespace):
## transformation drops documents

# Reds color palette
res<-rquery.wordcloud(filePath, type ="file", lang = "english",
                      colorPalette = "Reds")
## Warning in tm_map.SimpleCorpus(docs,
## content_transformer(tolower)): transformation drops documents
## Warning in tm_map.SimpleCorpus(docs, removeNumbers):
## transformation drops documents
## Warning in tm_map.SimpleCorpus(docs, removeWords,
## stopwords(lang)): transformation drops documents
## Warning in tm_map.SimpleCorpus(docs, removePunctuation):
## transformation drops documents
## Warning in tm_map.SimpleCorpus(docs, stripWhitespace):
## transformation drops documents

# RdBu color palette
res<-rquery.wordcloud(filePath, type ="file", lang = "english",
                      colorPalette = "RdBu")
## Warning in tm_map.SimpleCorpus(docs,
## content_transformer(tolower)): transformation drops documents
## Warning in tm_map.SimpleCorpus(docs, removeNumbers):
## transformation drops documents
## Warning in tm_map.SimpleCorpus(docs, removeWords,
## stopwords(lang)): transformation drops documents
## Warning in tm_map.SimpleCorpus(docs, removePunctuation):
## transformation drops documents
## Warning in tm_map.SimpleCorpus(docs, stripWhitespace):
## transformation drops documents

# use unique color
res<-rquery.wordcloud(filePath, type ="file", lang = "english",
                      colorPalette = "black")
## Warning in tm_map.SimpleCorpus(docs,
## content_transformer(tolower)): transformation drops documents
## Warning in tm_map.SimpleCorpus(docs, removeNumbers):
## transformation drops documents
## Warning in tm_map.SimpleCorpus(docs, removeWords,
## stopwords(lang)): transformation drops documents
## Warning in tm_map.SimpleCorpus(docs, removePunctuation):
## transformation drops documents
## Warning in tm_map.SimpleCorpus(docs, stripWhitespace):
## transformation drops documents

# Bar plot of the frequency for the top10
barplot(freqTable[1:10,]$freq, las = 2, 
        names.arg = freqTable[1:10,]$word,
        col ="lightblue", main ="Most frequent words",
        ylab = "Word frequencies")

url = "http://www.sthda.com/english/wiki/create-and-format-powerpoint-documents-from-r-software"
rquery.wordcloud(x=url, type="url")
## Warning in tm_map.SimpleCorpus(docs,
## content_transformer(tolower)): transformation drops documents
## Warning in tm_map.SimpleCorpus(docs, removeNumbers):
## transformation drops documents
## Warning in tm_map.SimpleCorpus(docs, removeWords,
## stopwords(lang)): transformation drops documents
## Warning in tm_map.SimpleCorpus(docs, removePunctuation):
## transformation drops documents
## Warning in tm_map.SimpleCorpus(docs, stripWhitespace):
## transformation drops documents
## Warning in wordcloud(d$word, d$freq, min.freq = min.freq,
## max.words = max.words, : packages could not be fit on page. It
## will not be plotted.
## Warning in wordcloud(d$word, d$freq, min.freq = min.freq,
## max.words = max.words, : recommended could not be fit on page.
## It will not be plotted.
## Warning in wordcloud(d$word, d$freq, min.freq = min.freq,
## max.words = max.words, : section could not be fit on page. It
## will not be plotted.
## Warning in wordcloud(d$word, d$freq, min.freq = min.freq,
## max.words = max.words, : survival could not be fit on page. It
## will not be plotted.
## Warning in wordcloud(d$word, d$freq, min.freq = min.freq,
## max.words = max.words, : underlined could not be fit on page. It
## will not be plotted.
## Warning in wordcloud(d$word, d$freq, min.freq = min.freq,
## max.words = max.words, : unordered could not be fit on page. It
## will not be plotted.
## Warning in wordcloud(d$word, d$freq, min.freq = min.freq,
## max.words = max.words, : visualize could not be fit on page. It
## will not be plotted.
## Warning in wordcloud(d$word, d$freq, min.freq = min.freq,
## max.words = max.words, : “title could not be fit on page. It
## will not be plotted.