## 연설문을 분석해서 word cloud 생성하기결과)
## noh.txt에 저장된 연설문을 분석하여 언급된 단어를 기준으로 워드 클라우드 생성
## 0. load library & setwd()
## 1. read data
## 2. extract noun
## 3. edit data
## 4. noun nchar >=2
## 5. save
## 6. read data as table
## 7. wordcloud
##
##
## 0. load library & setwd()
library(KoNLP)
library(wordcloud)
library(RColorBrewer)
getwd()
setwd("C:\\Users\\user\\Dropbox\\ADsP\\R Conqueror")
## 1. read data
txt = readLines("data/Part_1/LEVEL_1/noh.txt")
head(txt)
class(txt)
str(txt)
structure(txt)
## 2. extract noun
txt_nouns = sapply(txt, extractNoun, USE.NAMES=F)
head(txt_nouns, 30)
## 3. edit data
txt_nouns = gsub("\\d+", "",txt_nouns)
## 4. noun nchar >=2
txt_nouns = unlist(txt_nouns)
txt_nouns = Filter(function(x) {nchar(x) >=2}, txt_nouns)
## 5. save
write(txt_nouns,"noh_2.txt")
## 6. read data as table
rev = read.table("noh_2.txt")
nrow(rev)
wordcount = table(rev)
head(sort(wordcount, decreasing=T),30)
## 7. wordcloud
windows()
palete = brewer.pal(9,"Set1")
wordcloud(names(wordcount), freq=wordcount, scale=c(5,.5), rot.per= .25, min.freq=1, random.order=F, random.color = T, colors=palete)
2014년 11월 19일 수요일
연설문에서 world cloud 생성하기 II
피드 구독하기:
댓글
(
Atom
)
댓글 없음 :
댓글 쓰기