• R 语言词云wordcloud


    来源: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()
  • 相关阅读:
    Get-CrmSetting返回Unable to connect to the remote server的解决办法
    Dynamics 365中的常用Associate和Disassociate消息汇总
    Dynamics 365 Customer Engagement V9 活动源功能报错的解决方法
    Dynamics Customer Engagement V9版本配置面向Internet的部署时候下一步按钮不可点击的解决办法
    Dynamics 365检查工作流、SDK插件步骤是否选中运行成功后自动删除系统作业记录
    注意,更改团队所属业务部门用Update消息无效!
    Dynamics 365的审核日志分区删除超时报错怎么办?
    Dynamics 365使用Execute Multiple Request删除系统作业实体记录
    Dynamics 365的系统作业实体记录增长太快怎么回事?
    Dynamics CRM日期字段查询使用时分秒的方法
  • 原文地址:https://www.cnblogs.com/fkissx/p/5540118.html
Copyright © 2020-2023  润新知