Arvind S.P
Arvind S.P

Reputation: 1

using R how to draw wordcloud for my data

I want to make a wordcloud of the following dataframe (say DF):

MAKE        TYPE       PRICE
___________________________
subaru      hatchback   36
chevrolet   hatchback   53
mazda       truck       31
toyota      hatchback   39
mitsubishi  bus         41
honda       hatchback   42
nissan      sedan       37
dodge       hatchback   41
plymouth    hatchback   41
maruti      lorry       38
mitsubishi  hatchback   38
dodge       mini bus    38
plymouth    hatchback   38

What I was doing is as follows:

library(tm)
library(SnowballC)
library(wordcloud)

teleCorpus <- Corpus(VectorSource(DF$TYPE))

teleCorpus <- tm_map(teleCorpus, PlainTextDocument)

wordcloud(teleCorpus, max.words = 100, random.order = FALSE)

I want to make it look more pretty and colorful.

Can someone help, how to in different way then above???

Upvotes: 0

Views: 96

Answers (2)

Aadhya Manu Anand
Aadhya Manu Anand

Reputation: 87

You can also try...

require(RColorBrewer)

teleCorpus.tdm <- TermDocumentMatrix(teleCorpus)
teleCorpus.tdm.m <- as.matrix(teleCorpus.tdm)
teleCorpus.v <- sort(rowSums(teleCorpus.tdm.m),decreasing=TRUE)
teleCorpus.vd <- data.frame(word = names(teleCorpus.v), freq = teleCorpus.v)
table(teleCorpus.vd$freq)

pal2 <- brewer.pal(8,"Dark2")

wordcloud(teleCorpus.vd$word, teleCorpus.vd$freq, scale = c(8, 0.2), min.freq = 2, 
max.words=Inf, random.order = FALSE, rot.per = 0.15, colors = pal2)

Upvotes: 0

Felipe Sulser
Felipe Sulser

Reputation: 1195

Try using the following parameters to change the colors and layout:

wordcloud(teleCorpus, scale=c(5,0.5), max.words=100, random.order=FALSE, rot.per=0.35, use.r.layout=FALSE, colors=brewer.pal(8, “Dark2”))

Also, if you want to remove words you may do it as follows:

teleCorpus <- tm_map(teleCorpus, removeWords, “your_word_here”)

source: https://georeferenced.wordpress.com/2013/01/15/rwordcloud/

Upvotes: 2

Related Questions