Word Cloud (词云) - R
发布日期:2021-05-09 09:08:20 浏览次数:17 分类:博客文章

本文共 2593 字,大约阅读时间需要 8 分钟。

��������������������������������������� [Python](https://www.cnblogs.com/yukiwu/p/10967037.html) ��� [JavaScript](https://www.cnblogs.com/yukiwu/p/10968816.html) ������������������������������������ R��������� SPSS ��� SAS ��� Word Cloud ������������������������ R ������������
##### >> Create Word Cloud via R

  1. ���������������

��������������������������������������� Word Cloud History.txt ���������������������������������������������������������������������������������������������������������������������������������������������

  1. ������������������������ R ������
# Installinstall.packages("tm")  # for text mininginstall.packages("wordcloud") # word-cloud generator install.packages("RColorBrewer") # color palettes# Loadlibrary("tm")library("wordcloud")library("RColorBrewer")
  1. ��������������������������������������������������������������� inspect() ������������������������������������
#Read text filetext <- readLines(file.choose())# Load the data as a corpusdocs <- Corpus(VectorSource(text))#Inspect the content#inspect(docs)[1:10]
  1. ������������������������������ tm_map() ������������������������������������������������������������������������������������������
# Convert the text to lower casedocs <- tm_map(docs, content_transformer(tolower))# Remove numbersdocs <- tm_map(docs, removeNumbers)# Remove english common stopwordsdocs <- tm_map(docs, removeWords, stopwords("english"))# Remove punctuationsdocs <- tm_map(docs, removePunctuation)# Eliminate extra white spacesdocs <- tm_map(docs, stripWhitespace)
  1. ��������������������������������������� (words) ������������ (frequencies) ������������������ TermDocumentMatrix() ��������� text mining ������������������������������������ head() ������������������������
#Convert this into a matrix formatm <- as.matrix(dtm)#Gives you the frequencies for every wordv <- sort(rowSums(m),decreasing=TRUE)d <- data.frame(word = names(v),freq=v)#Scan the data#head(d, 10)
  1. ������ word cloud���
wordcloud(words = d$word, freq = d$freq, scale=c(5,0.5), min.freq = 1,          max.words=200, random.order=FALSE, rot.per=0.35,           colors=brewer.pal(8, "Accent"))

##### >> Notes

��������������� wordcloud() ������������������������������������������������������������������ help(wordcloud) ������ help(RColorBrewer) ���������������������������������

##### >> Sample Code

##### >> Related Blogs

1. [Word Cloud (������) - Python](https://www.cnblogs.com/yukiwu/p/10967037.html)2. [Word Cloud (������) - JavaScript](https://www.cnblogs.com/yukiwu/p/10968816.html)3. [Word Cloud (������) - Matlab](https://www.cnblogs.com/yukiwu/p/10971998.html)
上一篇:Word Cloud (词云) - Matlab
下一篇:Word Cloud (词云) - JavaScript

发表评论

最新留言

做的很好,不错不错
[***.243.131.199]2025年04月25日 12时50分28秒