码迷,mamicode.com
首页 > 编程语言 > 详细

R语言绘图:词云图

时间:2018-01-17 00:05:10      阅读:662      评论:0      收藏:0      [点我收藏+]

标签:cloud   find   scan   lis   fun   turn   pos   绘图   gpo   

使用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")

R语言绘图:词云图

标签:cloud   find   scan   lis   fun   turn   pos   绘图   gpo   

原文地址:https://www.cnblogs.com/xihehe/p/8297704.html

(1)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!