R语言词频统计与词云显示

时间:2022-07-23
本文章向大家介绍R语言词频统计与词云显示,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

未处理数据格式

image.png

处理数据 统计词频

image

text <- readLines("D:/Projects/rProjects/wordcloud/data.txt", encoding = "UTF-8")
txtList <- lapply(text, strsplit," ")
txtChar <- unlist(txtList)
txtChar <- gsub(pattern = """, replacement = "", txtChar)
data <- as.data.frame(table(txtChar))
colnames(data) = c("Word","freq")
ordfreq <- data[order(data$freq,decreasing = T),]
ordfreq

显示词云

wordcloud2(dataordfreq, size=2, shape='star', color='random-dark', backgroundColor="white", fontFamily="微软雅黑")

image