![e02d76a8b8d5ce934f2522a055d0d738.gif](https://img-blog.csdnimg.cn/img_convert/e02d76a8b8d5ce934f2522a055d0d738.gif)
26. 词云图绘制
清除当前环境中的变量
rm(list=ls())
设置工作目录
setwd("C:/Users/Dell/Desktop/R_Plots/26wordcloud/")
使用wordcloud2包绘制词云图
# 安装并加载所需R包
#install.packages("wordcloud2")
library(wordcloud2)
# 查看示例数据
# 第一列为词语名,第二列为词频数
head(demoFreq)
## word freq
## oil oil 85
## said said 73
## prices prices 48
## opec opec 42
## mln mln 31
## the the 26
# 使用wordcloud2函数绘制词云图
# 默认绘图
wordcloud2(demoFreq)
![273ca9cd5e23aa8ef21a23bff525d522.png](https://img-blog.csdnimg.cn/img_convert/273ca9cd5e23aa8ef21a23bff525d522.png)
# 设置字体大小和宽度
wordcloud2(demoFreq, size = 2, fontWeight = "bold")
![2f7325faf06ae528f8362a3d903774e6.png](https://img-blog.csdnimg.cn/img_convert/2f7325faf06ae528f8362a3d903774e6.png)
# shape参数设置词云展现图形
wordcloud2(demoFreq, size = 1,shape = 'star')
![2a33204545cfd85b1791f774823d7a92.png](https://img-blog.csdnimg.cn/img_convert/2a33204545cfd85b1791f774823d7a92.png)