gpt4 book ai didi

R:在 wordcloud 中传播单词

转载 作者:行者123 更新时间:2023-12-04 09:59:03 25 4
gpt4 key购买 nike

使用 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 保存输出功能,但这就是我得到的:
enter image description here

期望的输出:
enter image description here

最佳答案

我在 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

你最终得到:

enter image description here

创建于 2020-05-18 由 reprex package (v0.3.0)

关于R:在 wordcloud 中传播单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61869069/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com