mathhunの日記

Haskellと機械学習の勉強日記。PRML読みます。

R で wordcloud

Rでwordcloud描いてみた。
ネタは英語版Wikipediaから適当に MathematicsGaussLinear Algebraから。

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

ws <- Corpus(DirSource("~/tmp/wordcloud"))
#ws <- tm_map(ws, removeWhitespace)
ws <- tm_map(ws, removePunctuation)
ws <- tm_map(ws, tolower)
ws <- tm_map(ws, function(w) gsub("mathematics", "math", w))
ws <- tm_map(ws, removeWords, stopwords("english"))
ws <- tm_map(ws, removeWords, c("mathematical","isbn"))

png("math.png", width=1000, height=1000, units="px", res=300)
wordcloud(ws, scale=c(6,0.9), max.words=100, random.order=FALSE, rot.per=0.35, use.r.layout=FALSE, colors=brewer.pal(8,"Dark2"))
dev.off()

f:id:mathhun:20131120234607p:plain