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

2020-08-25 16:00:28 浏览数 (1)

未处理数据格式

image.png

处理数据 统计词频

image

代码语言:javascript复制
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

显示词云

代码语言:javascript复制
wordcloud2(dataordfreq, size=2, shape='star', color='random-dark', backgroundColor="white", fontFamily="微软雅黑")

image

0 人点赞