R语言学习笔记(二)词云图绘制

运用wordcloud函数

一、wordcloud函数介绍

函数帮助:通过help("wordcloud")查看

wordcloud(words,freq,scale=c(4,.5),min.freq=3,max.words=Inf,
random.order=TRUE, random.color=FALSE, rot.per=.1,
colors="black",ordered.colors=FALSE,use.r.layout=FALSE,
fixed.asp=TRUE, ...)
Arguments


words              
 the words
freq                        their frequencies
scale                A vector of length 2 indicating the range of the size of the words.
min.freq               words with frequency below min.freq will not be plotted
max.words      Maximum number of words to be plotted. least frequent terms dropped
random.order      plot words in random order. If false, they will be plotted in decreasing frequency
random.color       choose colors randomly from the colors. If false, the color is chosen based on the frequency
rot.per               proportion words with 90 degree rotation
colors               color words from least to most frequent
ordered.colors     if true, then colors are assigned to words in order
use.r.layout       if false, then c++ code is used for collision detection, otherwise R is used
fixed.asp               if TRUE, the aspect ratio is fixed. Variable aspect ratio only supported if rot.per==0
...
(二)参数中文介绍:

(1)words——关键词列表
(2)freq——关键词对应的词频列表
(3)scale——字号列表。c(最大字号, 最小字号)
(4)min.freq——最小限制频数。低于此频数的关键词将不会被显示。
(5)max.words——限制词云图上关键词的数量。最后出现在词云图上的关键词数量不超过此限制。
(6)random.order——控制关键词在图上的排列顺序。T:关键词随机排列;F:关键词按频数从图中心位置往外降序排列,即频数大的词出现在中心位置。
(7)random.color——控制关键词的字体颜色。T:字体颜色随机分配;F:根据频数分配字体颜色。
(8)rot.per——控制关键词摆放角度。T:水平摆放;F:旋转90度。
(9)colors——字体颜色列表
(10)ordered.colors——控制字体颜色使用顺序。T:按照指定的顺序给出每个关键词字体颜色,(似乎是要求颜色列表中每个颜色一一对应关键词列表);F:任意给出字体颜色。
(11)use.r.layout=T;F

(三)使用案例

1.安装程序包
install.packages("wordcloud")

2.加载程序包
library(wordcloud)

3.读取数据

R语言学习笔记(二)词云图绘制_第1张图片

data3=read.csv("E:/test45.csv")

4.运行函数

wordcloud(data3$words,data3$freq,scale=c(3,0.3),min.freq=-Inf,max.words=Inf,colors=brewer.pal(8,'Set1'),random.order=F,random.color=F,ordered.colors=F)

5.运行结果

R语言学习笔记(二)词云图绘制_第2张图片


你可能感兴趣的:(R语言)