R language word Cloud Wordcloud

Source: Internet
Author: User
Tags keyword list

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

    1. #加载wordcloud包
    2. Library (Wordcloud)
    3. #指定字体颜色范围    or use the ready-made theme template  colors=brewer.pal (8, "DARK2") in the R color package
    4. Colors=c (' Red ', ' blue ', ' green ', ' yellow ', ' purple ')
    5. #读取数据
    6. data=read.table ("/root/words.xa", header = F)
    7. #显示图形
    8. 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

    1. #设置保存图像的目录
    2. SETWD ("/tmp/")
    3. #设置保存图像的名字, background color, width and height
    4. PNG (file= "Wordcloud.png", bg= "white", Width = 480, height = 480)
    5. #加载wordcloud包
    6. Library (Wordcloud)
    7. #指定字体颜色范围 or Custom color range colors=c (' Red ', ' blue ', ' green ', ' yellow ', ' purple ')
    8. Colors=brewer.pal (8, "DARK2")
    9. #读取数据
    10. Data=read.table ("/root/words.xa", Header = F)
    11. #显示图形
    12. 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)
    13. #结束符
    14. Dev.off ()

R language word Cloud Wordcloud

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.