【问题标题】:R: Spreading the words in wordcloudR:在 wordcloud 中传播单词
【发布时间】:2020-05-18 21:42:25
【问题描述】:

在使用wordcloud 函数时,我正在努力宣传。

data = tibble(Day = c("January", "February", "March" , "April", "May", "June", "July", "August", "Semptember", "October", "November", "December"),
              Freq = c(1294, 1073, 1071, 1019, 938, 912, 703, 680, 543, 201, 190, 343))

set.seed(10)
wordcloud(words = data$Day, freq = data$Freq, min.freq = 1, 
          random.order=T, scale=c(3,.5), rot.per = 0)

我尝试使用ggsave 函数保存输出,但这就是我得到的:

期望的输出:

【问题讨论】:

  • 不确定我们是否有任何此类参数可以这样做,但作为一种解决方法,您可以将其缩放然后保存。

标签: r word-cloud


【解决方案1】:

我在wordcloud 中找不到执行此操作的方法,但wordcloud2 提供了更大的灵活性。我设法在另一个 SO 问题的帮助下将其拼凑在一起,以保存为图像文件。



#packages enable saving to png or pdf via html, see link at end of answer
library(webshot)
webshot::install_phantomjs()
library("htmlwidgets")


library(tibble)
library(wordcloud2)

data = tibble(Day = c("January", "February", "March" , "April", "May", "June", "July", "August", "Semptember", "October", "November", "December"),
              Freq = c(1294, 1073, 1071, 1019, 938, 912, 703, 680, 543, 201, 190, 343))


set.seed(10)

# control appearance with wordcloud2 arguments. The padding between words is controlled by `gridsize`.
# You have to play around with `size`, `gridSize` and the image size

eg <- wordcloud2(data, size = 0.4, rotateRatio = 0, color = "black", gridSize = 75)


# save as html
saveWidget(wc,"wc.html", selfcontained = F)


# and then as image:png
webshot("wc.html","wc.png", delay = 5, vwidth = 480, vheight = 480)


要将图像保存到文件,请参阅:How to Save the wordcloud in R

你最终得到:

reprex package (v0.3.0) 于 2020 年 5 月 18 日创建

【讨论】:

    猜你喜欢
    • 2017-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-10
    • 2021-10-25
    相关资源
    最近更新 更多