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。