R語言繪圖:詞雲圖


使用wordcloud2繪制詞雲圖

library(wordcloud2)
findwords<-function(tf){
        txt<-scan(tf,"")
        wl<-list()
        for(i in 1:length(txt)){
                wrd<-txt[i]
                wl[[wrd]]<-c(wl[[wrd]],i)
        }
        return(wl)
}
words<-findwords("testconcorda.txt")
wordfreq<-function(wrf){
        for(i in 1:length(wrf)){
                wrf[[i]]<-length(wrf[[i]])
        }
return(wrf)
}
wrf<-wordfreq(words)
data<-function(dt){
        word<-names(dt)
        count<-c()
        for(i in 1:length(dt)){
                count[i]<-dt[[i]]
        }
        wordcloud<-data.frame(word,count)
        return(wordcloud)
}
data1<-data(wrf)
wordcloud2(data1,color="random-light",backgroundColor = "grey")


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM