R语言中绘制词云图


R语言中绘制词云图使用的是wordcloud2包中的wordcloud2()函数

wordcloud2() 用法介绍

wordcloud2(data, size = 1, minSize = 0, gridSize =  0,
    fontFamily = 'Segoe UI', fontWeight = 'bold',
    color = 'random-dark', backgroundColor = "white",
    minRotation = -pi/4, maxRotation = pi/4, shuffle = TRUE,
    rotateRatio = 0.4, shape = 'circle', ellipticity = 0.65,
    widgetsize = NULL, figPath = NULL, hoverFunction = NULL)

重要参数及含义

  • data
    A data frame including word and freq in each column

  • size
    Font size, default is 1. The larger size means the bigger word.

  • minSize
    A character string of the subtitle

  • gridSize
    Size of the grid in pixels for marking the availability of the canvas the larger the grid size, the bigger the gap between words.

  • fontFamily
    Font to use.

  • fontWeight
    Font weight to use, e.g. normal, bold or 600

  • color
    color of the text, keyword ‘random-dark’ and ‘random-light’ can be used. color vector is also supported in this param

  • backgroundColor
    Color of the background.

  • minRotation
    If the word should rotate, the minimum rotation (in rad) the text should rotate.

  • maxRotation
    If the word should rotate, the maximum rotation (in rad) the text should rotate. Set the two value equal to keep all text in one angle.

  • shape
    The shape of the “cloud” to draw. Can be a keyword present. Available presents are ‘circle’ (default), ‘cardioid’ (apple or heart shape curve, the most known polar equation), ‘diamond’ (alias of square), ‘triangle-forward’, ‘triangle’, ‘pentagon’, and ‘star’.

  • figPath
    The path to a figure used as a mask.

letterCloud()用法介绍

letterCloud(data, word, wordSize = 0, letterFont = NULL, ...)

重要参数及含义

  • data
    A data frame including word and freq in each column

  • word
    A word to create shape for wordcloud.

  • wordSize
    Parameter of the size of the word.

  • letterFont
    Letter font


  • Other parameters for wordcloud

实例

实例1

library(wordcloud2)
wordcloud2(demoFreqC, size = 2, minSize = 20,color = "random-light", backgroundColor = "grey",minRotation = -pi/6, maxRotation = -pi/6,
           rotateRatio = 1,shape="cardioid")

在这里插入图片描述

实例2

letterCloud(demoFreq,"R")

在这里插入图片描述

一个bug

最新版本的wordcloud2包不能实现自定义图片背景,这是因为最新版本存在一个bug, 可以尝试使用老版本wordcloud2_0.2.0。

https://blog.csdn.net/tandelin/article/details/103977242?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-1.pc_relevant_aa&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-1.pc_relevant_aa&utm_relevant_index=2

  • 2
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值