Source: http://blog.chinaunix.net/uid-25135004-id-4311592.html
Wordcloud function--to draw a word cloud
Usage:
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, ...)
Parameters
1) Words---keyword list
The words
2) Freq---keywords corresponding to the word frequency list
Their frequencies
3) Scale---display a range of font sizes, such as C (3,0.3), the maximum font is 3, and the minimum font size is 0.3
A vector of length 2 indicating the range of the size of the words
4) Min.freq---minimum word frequency, words below the minimum frequency are not displayed
Words with frequency below min.freq won't be plotted
5) Max.words---The maximum number of words to display.
Maximum number of words to be plotted. Least frequent terms dropped
6) Random.order---the order in which the words are arranged on the graph. T: Words are randomly arranged, F: the words are arranged in descending order of the frequency heart position, that is, the words with large frequency appear in the central position.
Plot words in random order. If false, they'll is plotted in decreasing frequency
7) Random.color---control the font color of the word. T: Font color is randomly assigned; F: assigns font color based on frequency.
Choose colors randomly from the colors. If false, the color is chosen based on the frequency
8) Rot.per---control word placement angle. T: rotate 90 degrees; F: Horizontal.
Proportion words with degree rotation
9) Colors---font Color list
Color words from least to most frequent
) ordered.colors---controls the order in which font colors are used. T: Give the font color of each keyword in the order specified, (appears to require a list of keywords for each color in the color list), and F: Give the font color in any way.
If true, then colors is assigned to words in order
One) use.r.layout
If False, then C + + code is used-collision detection, otherwise R is used
fixed.asp)
If TRUE, the aspect ratio is fixed. Variable aspect ratio only supported if rot.per==0
13)...
Additional parameters to is passed to text (and Strheight,strwidth).
Details
If freq is missing, then words can either be a character vector, or Corpus. If it is a vector and freq is
Missing, standard stop words is removed prior to plotting.
Installation:
Install.packages (' Wordcloud ')
Example:
Wordcloud (c (Letters, letters, 0:9), seq (1, +, Len = 62))
Specific Use examples:
1. Example of direct image display
Click ( here) to collapse or open
- #加载wordcloud包
- Library (Wordcloud)
- #指定字体颜色范围 or use the ready-made theme template colors=brewer.pal (8, "DARK2") in the R color package
- Colors=c (' Red ', ' blue ', ' green ', ' yellow ', ' purple ')
- #读取数据
- data=read.table ("/root/words.xa", header = F)
- #显示图形
- wordcloud (Data$v2,data$v1,scale=c (5,0.3), Min.freq=-inf,max.words=60,colors=colors, RANDOM.ORDER=F,RANDOM.COLOR=F,ORDERED.COLORS=F)
2. Save the image as PNG
Click ( here) to collapse or open
- #设置保存图像的目录
- SETWD ("/tmp/")
- #设置保存图像的名字, background color, width and height
- PNG (file= "Wordcloud.png", bg= "white", Width = 480, height = 480)
- #加载wordcloud包
- Library (Wordcloud)
- #指定字体颜色范围 or Custom color range colors=c (' Red ', ' blue ', ' green ', ' yellow ', ' purple ')
- Colors=brewer.pal (8, "DARK2")
- #读取数据
- Data=read.table ("/root/words.xa", Header = F)
- #显示图形
- Wordcloud (Data$v2,data$v1,scale=c (5,0.3), min.freq=-inf,max.words=60,colors=colors,random.order=f,random.color= F,ORDERED.COLORS=F)
- #结束符
- Dev.off ()
R language word Cloud Wordcloud