未处理数据格式
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