政务系统留言词云图
对政务系统对留言,进行分词,词频统计并生成词云图。
library(wordcloud2)
library(rJava)
library(Rwordseg)
library(RColorBrewer)
library(wordcloud)
library(tmcn)
library(tm)
library(readxl)
library(stringr)
library(xlsx)
library(readxl)
data<-read_xlsx('C:/Mathmodel/Python/lawless/附件3.xlsx')#这个会直接默认读取到这个Excel的第一个表单
wsjs<-data$留言主题
res=wsjs[]
wsjs_words=unlist(lapply(X=res, FUN=segmentCN))
stop_words<-read.csv("C:/Mathmodel/Python/分类停用词/stopwords_1.txt",encoding="utf-8",header=FALSE)
stopwords<-unlist(stop_words)
w_wordResult <- removeWords(w_words,stopwords)
w_v=table(unlist(w_wordResult))#table统计数据的频数
# 降序排序
w_v=rev(sort(w_v))#词频
w_d=data.frame(词汇=names(w_v), 词频=w_v)
w_d=subset(w_d,nchar(as.character(w_d$词汇))>1)##去掉单字后的分词
w_d=subset(w_d, w_d$词频.Freq>=10)##去掉词频少于10的画词云图
w_a<-wsjs_d[2:3]
wordcloud2(w_a,size=1)