来源:http://blog.chinaunix.net/uid-25135004-id-4311592.html

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, ...)

参数
 1)words --- 关键词列表
                   the words
 2)freq---关键词对应的词频列表
               their frequencies
 3)scale---显示字体大小的范围,例如c(3,0.3),最大字体是3,最小字体是0.3
               A vector of length 2 indicating the range of the size of the words
 4)min.freq---最小词频,低于最小词频的词不会被显示
                   words with frequency below min.freq will not be plotted
 5)max.words---显示的最大词数量。
                       Maximum number of words to be plotted. least frequent terms dropped
 6)random.order---词在图上的排列顺序。T:词随机排列;F:词按频数从图中心位置往外降序排列,即频数大的词出现在中心位置。
                           plot words in random order. If false, they will be plotted in decreasing frequency
 7)random.color---控制词的字体颜色。T:字体颜色随机分配;F:根据频数分配字体颜色。
                           choose colors randomly from the colors. If false, the color is chosen based on the frequency
 8)rot.per---控制词摆放角度。T:旋转90度;F:水平摆放。
                    proportion words with 90 degree rotation
 9)colors---字体颜色列表
                   color words from least to most frequent
 10)ordered.colors---控制字体颜色使用顺序。T:按照指定的顺序给出每个关键词字体颜色,(似乎是要求颜色列表中每个颜色一一对应关键词列表);F:任意给出字体颜色。
                                if true, then colors are assigned to words in order
 11)use.r.layout
                if false, then c++ code is used for collision detection, otherwise R is used
 12) fixed.asp 
               if TRUE, the aspect ratio is fixed. Variable aspect ratio only supported if rot.per==0
 13) ... 
             Additional parameters to be 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 will be removed prior to plotting.

安装:
install.packages('wordcloud')

例子:
wordcloud(c(letters, LETTERS, 0:9), seq(1, 1000, len = 62))

具体使用例子:

1、直接显示图像的例子

点击(此处)折叠或打开

  1. #加载wordcloud包
  2. library(wordcloud)
  3. #指定字体颜色范围  或者使用R颜色程序包中现成的主题模板 colors=brewer.pal(8,"Dark2")
  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、把图像保存为png

点击(此处)折叠或打开

  1. #设置保存图像的目录
  2. setwd("/tmp/")
  3. #设置保存图像的名字,背景颜色,宽度和高度
  4. png(file="wordcloud.png", bg="white",width = 480, height = 480)
  5. #加载wordcloud包
  6. library(wordcloud)
  7. #指定字体颜色范围 或者自定义颜色范围 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 语言词云wordcloud的更多相关文章

  1. scrapy-redis爬取豆瓣电影短评,使用词云wordcloud展示

    1.数据是使用scrapy-redis爬取的,存放在redis里面,爬取的是最近大热电影<海王> 2.使用了jieba中文分词解析库 3.使用了停用词stopwords,过滤掉一些无意义的 ...

  2. 大数据工具比较:R 语言和 Spark 谁更胜一筹?

    本文有两重目的,一是在性能方面快速对比下R语言和Spark,二是想向大家介绍下Spark的机器学习库 背景介绍 由于R语言本身是单线程的,所以可能从性能方面对比Spark和R并不是很明智的做法.即使这 ...

  3. 掌握R语言中的apply函数族(转)

    转自:http://blog.fens.me/r-apply/ 前言 刚开始接触R语言时,会听到各种的R语言使用技巧,其中最重要的一条就是不要用循环,效率特别低,要用向量计算代替循环计算. 那么,这是 ...

  4. 词云-wordcloud

    import jiebabook = "2015.txt"txt = open(book).read()ex = {'不是','就是','的话','1.1','docin','ww ...

  5. R语言中的factor

    对于初学者来说,R语言中的factor有些难以理解.如果直译factor为“因子”,使得其更加难以理解.我倾向于不要翻译,就称其为factor,然后从几个例子中理解: <span style=& ...

  6. R语言中apply函数

    前言 刚开始接触R语言时,会听到各种的R语言使用技巧,其中最重要的一条就是不要用循环,效率特别低,要用向量计算代替循环计算. 那么,这是为什么呢?原因在于R的循环操作for和while,都是基于R语言 ...

  7. R语言中的MySQL操作

    R语言中,针对MySQL数据库的操作执行其实也有很多中方式.本人觉得,熟练掌握一种便可,下面主要就个人的学习使用情况,总结其中一种情况-----使用RMySQL操作数据库. 1.下载DBI和RMySQ ...

  8. 词云wordcloud入门示例

    整体简介: 词云图,也叫文字云,是对文本中出现频率较高的“关键词”予以视觉化的展现,词云图过滤掉大量的低频低质的文本信息,使得浏览者只要一眼扫过文本就可领略文本的主旨. 基于Python的词云生成类库 ...

  9. 词云wordcloud类介绍&python制作词云图&词云图乱码问题等小坑

    词云图,大家一定见过,大数据时代大家经常见,我们今天就来用python的第三方库wordcloud,来制作一个大数据词云图,同时会降到这个过程中遇到的各种坑, 举个例子,下面是我从自己的微信上抓的微信 ...

随机推荐

  1. 【Pascal's Triangle II 】cpp

    题目: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [ ...

  2. 1.0 python-client以及ui自动化介绍

     appium的client-----捕获元素和对元素进行操作都是在client里面去写脚本实现的,client会将你写的python脚本发送到appium server上,然后appium serv ...

  3. diskimage-builder-command

    yum -y install python-virtualenv.noarch virtualenv ~/dib-virtualenv . ~/dib-virtualenv/bin/activate ...

  4. ssh.sh_for_ubuntu1404

    #!/bin/bash sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/g' /etc/ssh/sshd_config s ...

  5. 第十六篇:django基础

    本篇内容 创建程序 程序目录 流程介绍 login实例 一.创建程序 命令行: django-admin startproject sitename. 常用命令: python manage.py r ...

  6. 【bzoj3585/bzoj3339】mex/Rmq Problem 莫队算法+分块

    原文地址:http://www.cnblogs.com/GXZlegend/p/6805283.html 题目描述 有一个长度为n的数组{a1,a2,...,an}.m次询问,每次询问一个区间内最小没 ...

  7. DataBase -- SQL INNER JOIN

    SQL INNER JOIN 关键字 在表中存在至少一个匹配时,INNER JOIN关键字返回行. INNER JIN关键字语法 SELECT column_name(s) FROM table_na ...

  8. 【BZOJ 2809 dispatching】

    Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 4393  Solved: 2246[Submit][Status][Discuss] Descript ...

  9. For Path

    /****** Script for SelectTopNRows command from SSMS ******/ DECLARE @table TABLE (姓名 VARCHAR(10),课程 ...

  10. SpringBoot Redis序列化配置

    Redis配置 #Redis spring.redis.host= spring.redis.port=6379 spring.redis.database=0 # Redis服务器连接密码(默认为空 ...