You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将词云适配/缩放至图表以消除白色边框?

词云尺寸过小、白色边框问题的解决方法

使用textplot_wordcloud()生成词云时,出现词云占比过小、周围存在多余白色边框的问题,示例代码及效果如下:

set.seed(100)

png(file=paste( path to save file)) 

textplot_wordcloud(dfm_inaug, rotation = 0.0, min_size = 0.5, max_size
= 3, color = c("skyblue3",  "darkblue"))

dev.off()

词云效果图片

解决步骤:

  • 消除绘图边距:在绘制词云前调用par(mar = c(0, 0, 0, 0)),将绘图区域的上下左右边距全部设为0,去除默认的空白边框。
  • 调大字号范围:增大max_size参数的值(比如改为5或更大),让最大的词能占据更多空间,同时可根据需求微调min_size,保证小词也能合理展示。
  • 适配画布尺寸:在png()函数中明确指定width和height参数(如width=800, height=800),匹配你需要的输出尺寸,还可设置bg="transparent"得到透明背景的词云。
  • 开启自动缩放:在textplot_wordcloud()中添加rescale = TRUE参数,让词云自动适配当前绘图区域的大小。

修改后的完整代码示例:

set.seed(100)
# 自定义画布尺寸,按需调整宽高数值
png(file = "your_save_path.png", width = 800, height = 800)
# 清除所有边距
par(mar = c(0, 0, 0, 0))
textplot_wordcloud(dfm_inaug, 
                   rotation = 0.0, 
                   min_size = 0.5, 
                   max_size = 5, 
                   color = c("skyblue3", "darkblue"),
                   rescale = TRUE)
dev.off()

内容的提问来源于stack exchange,提问作者Mateo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 16:20:42