rword-cloud

R: How to put a wordcloud plot in a variable?


I could be this is a beginners question, but I am working with ggplot2 a lot so I hadn't noticed this before as wordcloud is not ggplot2 function: I don't seem to be able to put my wordcloud into a variable.

When I do this:

library(wordcloud)
myvariable <- wordcloud(mywords, other_parameters...)

Then myvariable has NULL.

Is this known behaviour and is it even possible to put a wordcloud into a varible? If yes, how should I do that? Many thanks in advance!


Solution

  • You can't. wordcloud() is based on base graphics. When you call those functions, they have the side effect of drawing to the current graphics device. You could copy or save the results of the graphics device somewhere -- but not as an R object.

    Why do you think you need to save the result? It would be best just not to call the function until you are read to render it.