3

Can you please help to save word cloud on my local drive as an image?, I am looking for a code/command to get it done automatically through R Programming. I have tried with saveWidget, plotly, orca but not get success.

I have used below code to create the word cloud.

library(wordcloud2)
wordcloud2(demoFreqC, figPath = figPath,color = "orangered",fontFamily = "Miso")
markus
  • 25,843
  • 5
  • 39
  • 58
sanjay saini
  • 111
  • 2
  • 2
  • 6

3 Answers3

8

The procedure is outlined here. Briefly:

library(htmlwidgets) 
install.packages("webshot")
webshot::install_phantomjs()
library(wordcloud2)
hw <- wordcloud2(demoFreq,size = 3)
saveWidget(hw,"1.html",selfcontained = F)
webshot::webshot("1.html","1.png",vwidth = 1992, vheight = 1744, delay =10)
Hack-R
  • 22,422
  • 14
  • 75
  • 131
neilfws
  • 32,751
  • 5
  • 50
  • 63
  • I have tried this code but not able to get the output can you please tell me where the output got stored, as it is not showing in my current working directory. – sanjay saini Aug 09 '18 at 07:59
  • Should be in your working directory if everything worked. I had to add `library(htmlwidgets)` to get `saveWidget()` working. – neilfws Aug 09 '18 at 10:52
  • the HTML file 1.html saved in my working directory and I am able to access it but not able to find the 1.png file. – sanjay saini Aug 09 '18 at 11:10
  • If `webshot()` ran without error, it has to be there somewhere :) – neilfws Aug 09 '18 at 11:12
  • Your working directory is probably set to something you don't expect @sanjaysaini . Check your Rstudio options to see where your working directory is, or use `getwd()`. Always best to specify absolute paths to files when working in Rstudio. – wordsforthewise Apr 17 '19 at 00:15
  • Delay seems to work with 5s for me (https://stackoverflow.com/a/47850987/4549682). It needs to be large enough to let the wordcloud render. Might be machine-dependent. – wordsforthewise Apr 17 '19 at 00:17
0

If you are using RStudio, there is an option to import the output as image on the IDE itself.

sss
  • 598
  • 6
  • 24
0

in R studio there is an option to export the plot in JPG or PNG format with the image size you want.

Hunaidkhan
  • 1,411
  • 2
  • 11
  • 21