2019년 8월 26일 월요일

Chp3. WORD_CLOUD - 3

본론
1-1-3 Word Cloud 생성 Mission - 1

Step - 1
패키지 load

library(rJava)
library("KoNLP")
library("wordcloud")

Step - 2
소스파일 로딩

txt <- readLines("hong.txt")
txt
-->입력해서 잘 불러오기가 됫는지 확인한다
pol <- sapply(txt,extractNoun,USE.NAMES=F)

Step - 3
불필요 단어 제거

c <- unlist(pol)
res <- Filter(function(x) {nchar(x) >=2},c)
res <- gsub("홍길동","",res)

Step - 4
정리된 데이터 파일 txt로 저장
write(unlist(res),"hong_res.txt")
tot <- readLines("hong_res.txt")
nrow(tot)
wordcount <- table(tot)
head(sort(wordcount,decreasing=T),20)

Step - 5
글자색 설정후 wordcloud 생성
library(RColorBrewer)
palete <- brewer.pal(9,"Set1")
wordcloud(names(wordcount),freq=wordcount,sale=c(5,0.5),rot.per=0.25,min_freq=2,random.pro=F,random.color=T,color=palete)

Step - 6
이미지 파일 저장
savePlot("pol_hong.png",type="png")

댓글 없음:

댓글 쓰기