Quantcast
Channel: SCN : All Content - SAP BusinessObjects Predictive Analytics
Viewing all articles
Browse latest Browse all 836

Create Word Cloud using R

$
0
0

A word cloud is a visual representation for text data, typically used to visualize free form text. This format is useful for quickly perceiving the most prominent terms and for locating a term alphabetically to determine its relative prominence.

A  word cloud on most used statistical term from the description of 3177 available R packages in cran website.

 

Syntax -

 

 

install.packages("wordcloud")

install.packages("RColorBrewer")

require(wordcloud)

require(RColorBrewer)

 

docs<-c("here your text will appear") 

 

#VectorSource could also be DataframeSource, DirSource, URISource, XMLSource
mycorpus<- Corpus(VectorSource(docs))


#if you are reading from .CSV file then use following syntax

#mycorpus<-read.csv(file.path(path, datafiles))

tdm <- TermDocumentMatrix(mycorpus)
m <- as.matrix(tdm)
v <- sort(rowSums(m),decreasing=TRUE)
d <- data.frame(word = names(v),freq=v)

pal <- brewer.pal(9,"BuGn")

 

#make the word cloud

wordcloud(dm$word, dm$freq, random.order=FALSE, colors=brewer.pal(8, "Dark2"))

 

 

word_cloud.PNG


Viewing all articles
Browse latest Browse all 836

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>