# Install and load the required packages
# for text mining
[Link]("tm")
# for text stemming
[Link]("SnowballC")
# for word-cloud generator
[Link]("wordcloud")
# for colour palettes
[Link]("RColorBrewer")
# Add to the Library
library("tm")
library("SnowballC")
library("wordcloud")
library("RColorBrewer")
#Load the data as a corpus
docs <- Corpus(VectorSource(Text))
#Build a term-document matrix
Term <- TermDocumentMatrix(docs)
Matrix <- [Link](Term)
Sort <- sort(rowSums(Matrix),decreasing=TRUE)
Key <- [Link](word = names(Sort),freq=Sort)
Key
head(Key, 10)
#Cleaning the text
# Convert the text to lower case
docs <- tm_map(docs, content_transformer(tolower))
# Remove numbers
docs <- tm_map(docs, removeNumbers)
# Remove english common stopwords
docs <- tm_map(docs, removeWords, stopwords("english"))
# Remove your own stop word # specify your stopwords as a character vector
docs <- tm_map(docs, removeWords, c("blabla1", "blabla2"))
# Remove punctuations
docs <- tm_map(docs, removePunctuation)
# Build a term-document matrix
Term <- TermDocumentMatrix(docs)
Matrix <- [Link](Term)
Sort <- sort(rowSums(Matrix),decreasing=TRUE)
Key <- [Link](word = names(Sort),freq=Sort)
Key
head(Key, 10)
#How to save data
[Link](Key,"[Link]", [Link] = FALSE)
#Generate the Word cloud
[Link](1234)
wordcloud(words = Key$word, freq = Key$freq, [Link] = 1,
[Link]=200, [Link]=FALSE, [Link]=0.35,
colors=[Link](8, "Dark2"))
#Explore frequent terms
findFreqTerms(Term, lowfreq = 4)