美文网首页
R语言词频统计与词云显示

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

作者: ZZES_ZCDC | 来源:发表于2020-08-01 10:30 被阅读0次

未处理数据格式

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

相关文章

网友评论

      本文标题:R语言词频统计与词云显示

      本文链接:https://www.haomeiwen.com/subject/hyoplktx.html