install.packages("rJava")
install.packages("memois")
install.packages("KoNLP", dependencies = T)
install.packages("stringr")
install.packages("wordcloud",dependencies = T)
library(KoNLP)
library(dplyr)
library(stringr)
library(wordcloud)
library(RColorBrewer)
useNIADic()
hiphop<-readLines("hiphop.txt", encoding = "UTF-8")
head(hiphop)
hiphop<-str_replace_all(hiphop,"\W"," ")
head(hiphop)
nouns<-extractNoun(hiphop)
wordcount<-table(unlist(nouns))
head(wordcount)
df_word<-as.data.frame(wordcount, stringsAsFactors = F)
df_word
df_word<-rename(df_word, var1=Var1,freq=Freq)
head(df_word)
df_word<-filter(df_word, nchar(var1) >= 2)
head(df_word)
top20<-df_word %>%
arrange(desc(freq)) %>%
head(20)
top20
pal<-brewer.pal(8,"Dark2")
set.seed(1234)
wordcloud(words=df_word$word,
freq=df_word$freq,
min.freq=2,
max.words=200,
random.order=F,
rot.per=.1,
scale=c(4,0.3),
colors=pal)
이렇게 했는데 다음과 같은 오류가 나타납니다.
Error in if (grepl(tails, words[i])) ht <- ht + ht * 0.2 :
인자의 길이가 0입니다
이럴 경우 어떻게 해야 워드클라우드를 그릴 수 있을까요?