[英]R: Spreading the words in wordcloud
I'm struggling to spread the words when using wordcloud
function.使用wordcloud
function 时,我正在努力宣传。
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)
I tried to save the output using ggsave
function but this is what I got:我尝试使用ggsave
function 保存 output 但这就是我得到的:
I couldn't find a way to do this in wordcloud
but wordcloud2
gives rather more flexibility.我在wordcloud
中找不到这样做的方法,但wordcloud2
提供了更大的灵活性。 I managed to cobble together this with help from another SO question for saving as an image file.我设法在另一个 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)
For saving the image to file see: How to Save the wordcloud in R要将图像保存到文件,请参阅: 如何在 R 中保存 wordcloud
And you end up with:你最终得到:
Created on 2020-05-18 by the reprex package (v0.3.0)由代表 package (v0.3.0) 于 2020 年 5 月 18 日创建
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.