汉语词云

Chinese Word Cloud

发布于

2024年1月25日

汉语词云

汉语词云

1 使用R

# library ###################################################################
library(readxl)
library(jiebaR)
library(tmcn)
library(wordcloud2)
library(htmlwidgets)
library(webshot)

# wd ########################################################################
setwd("")

# read data #################################################################
dat <- read_xlsx("")
dat[,23] <- NULL
vlabels <- names(dat)
names(dat) <- c()

# 分词 ######################################################################
## stop words 
writeLines(stopwordsCN(stopwords = c("无","1","2","3","️","情绪"),
                       useStopDic = TRUE),
           "STOPWORDS.txt")

## Using default settings to initialize a worker.
cutter = worker(stop_word="STOPWORDS.txt")

##  分词
words <- segment(dat$emo_known, cutter)

## 词频表
words.df <- data.frame(freq(words))
words.df <- words.df[order(words.df$freq,decreasing =TRUE),]
# head(words.df,20)
names(words.df) <- c("word","freq")

# 词云 ######################################################################
emo_html <- wordcloud2(words.df,color = "lightpink",shape = 'cardioid')
saveWidget(emo_html,"emo_wordcloud.html",selfcontained = T)
## 提前安装webshot,并运行`install_phantomjs()`安装phantomjs
webshot("emo_wordcloud.html", file = "emo_wordcloud.png",
        delay=10,vheight=1000)

2 其他方法

2.1 Credamo

Credamo具备一定的数据分析功能。免费版即包含“词云分析”功能。