2

I'm struggling to spread the words when using 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: enter image description here

Desired output: enter image description here

nikn8
  • 1,016
  • 8
  • 23
Pawliczek
  • 53
  • 5
  • not sure if we have any such parameter to do so, but as a work around, you can zoom it and then save it. – nikn8 May 18 '20 at 13:31

1 Answers1

2

I couldn't find a way to do this in wordcloud but wordcloud2 gives rather more flexibility. I managed to cobble together this with help from another SO question for saving as an image file.



#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

And you end up with:

enter image description here

Created on 2020-05-18 by the reprex package (v0.3.0)

Peter
  • 11,500
  • 5
  • 21
  • 31