Created
August 22, 2012 11:15
-
-
Save emres/3424557 to your computer and use it in GitHub Desktop.
A very simple word cloud generation code in R
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tm) | |
library(wordcloud) | |
library(RColorBrewer) | |
my.corpus = Corpus(DirSource("directory_containing_files_to_be_processed")) | |
my.corpus <- tm_map(my.corpus, tolower) | |
my.corpus <- tm_map(my.corpus, stripWhitespace) | |
my.corpus <- tm_map(my.corpus, removePunctuation) | |
my.corpus <- tm_map(my.corpus, removeWords, stopwords("english")) | |
tdm <- TermDocumentMatrix(my.corpus) | |
m1 <- as.matrix(tdm) | |
v1<- sort(rowSums(m1),decreasing=TRUE) | |
d1<- data.frame(word = names(v1),freq=v1) | |
#wordcloud(d1$word, d1$freq, min.freq=3) | |
pal <- brewer.pal(9,"BuGn") | |
pal <- pal[-(1:4)] | |
pal2 <- brewer.pal(8,"Dark2") | |
png("wordcloud.png", width=1280,height=800) | |
wordcloud(d1$word, d1$freq, | |
scale=c(8,.3), min.freq = 2, max.words = 100, | |
use.r.layout = FALSE, | |
random.order=T, rot.per=.15, | |
colors = pal2) | |
#, vfont=c("sans serif","plain")) | |
dev.off() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment