R 语言词云wordcloud

转载 自 http://blog.chinaunix.net/uid-25135004-id-4311592.html
参数
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 的包,那么,手动下载,然后在rstudio 中导入即可
https://cran.r-project.org/src/contrib/Archive/wordcloud/

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

1、直接显示图像的例子



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



    #设置保存图像的目录
    setwd("/tmp/")
    #设置保存图像的名字,背景颜色,宽度和高度
    png(file="wordcloud.png", bg="white",width = 480, height = 480)
    #加载wordcloud包
    library(wordcloud)
    #指定字体颜色范围 或者自定义颜色范围 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()

这里写图片描述



    6387 尸体
    5765 提示
    5598 距离
    5579 知道
    5372 绿竹
    4682 打架
    4521 挂机
    4150 序号
    3882 地宫
    3266 时候
    3202 装备
    3183 回来
    3177 队长
    3148 活力
    3125 武当
    3104 小号
    3032 睡觉
    2975 速度
    2970 干嘛
    2956 五仙
    2800 出来
    2731 技能
    2563 东西
    2468 华山
    2449 峨眉
    2438 个人
    2396 没事
    2326 师傅
    2304 看看
    2299 时间
    2299 活动
    2291 不了
    2247 不会
    2199 老婆
    2092 任务
    2079 沙子
    2061 游戏
    2038 看到
    1952 不在
    1934 衣服
    1909 蜘蛛
    1908 盟主
    1907 副本
    1887 不能
    1878 出去
    1873 力道
    1872 帮派
    1818 少林
    1813 前锋
    1798 武器
    1754 升级
    1753 大军
    1729 朋友
    1711 代价
    1679 应该
    1672 不用
    1575 衡山
    1571 意思
    1561 经验
    1558 时装
    1534 喜欢
    1530 徒弟
    1527 龙陵
    1523 队伍
    1517 垃圾
    1509 好像
    1505 巨兽
    1481 宝石
    1458 起来
    1445 准备
    1445 交易
    1438 谢谢
    1425 世界
    1397 合成
    1386 打手
    1381 感觉
    1380 妹子
    1376 百度
    1375 助手
    1369 吃饭

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值