title: Subplot/facets with wordclouds
body: <p>I'm trying to make subplots/facets of several wordclouds in a way that's
  pleasing to the eye.</p>
  
  <p>Problems:</p>
  
  <ol>
  <li>I can't get base R to combine <code>wordcloud</code>-outputs properly</li>
  <li>making wordclouds with <code>ggplot2</code> allows for facetting but yields unsatisfactory results
   (ugly positioning)</li>
  </ol>
  
  <p>I've tried to two ways to create these wordcloud-subplots. </p>
  
  <h2>1. I create an example dataset (following <a href="http://tidytextmining.com/sentiment.html#wordclouds" rel="noreferrer">here</a>):</h2>
  
  <pre><code>library(dplyr)
  library(janeaustenr)
  library(tidytext)
  
  df &lt;- austen_books() %&gt;%
    unnest_tokens(word, text) %&gt;% 
    anti_join(stop_words, by = "word") %&gt;%
    group_by(book) %&gt;%
    count(word) %&gt;% 
    top_n(100, n)
  </code></pre>
  
  <h2>2. My first try uses the <code>wordcloud</code> package and base R:</h2>
  
  <pre><code>library(wordcloud)
  
  par(mfrow = c(2,2))
  png("jane_austen_wordclouds.png")
  
  df %&gt;% 
    filter(book == "Sense &amp; Sensibility") %&gt;% 
    with(wordcloud(word, n))
  
  df %&gt;% 
    filter(book == "Pride &amp; Prejudice") %&gt;% 
    with(wordcloud(word, n))
  
  df %&gt;% 
    filter(book == "Mansfield Park") %&gt;% 
    with(wordcloud(word, n))
  
  df %&gt;% 
    filter(book == "Emma") %&gt;% 
    with(wordcloud(word, n))
  
  title( "Jane Austen Word Clouds", outer = TRUE)
  dev.off() 
  </code></pre>
  
  <p>Creating:</p>
  
  <p><a href="https://i.stack.imgur.com/h9uqg.png" rel="noreferrer"><img src="https://i.stack.imgur.com/h9uqg.png" alt="enter image description here"></a></p>
  
  <p>So somehow it only saves the last subplot. If I don't use <code>png("jane_austen_wordclouds.png")</code> and <code>dev.off()</code> and just save the figure straight from RStudio, then I get:</p>
  
  <p><a href="https://i.stack.imgur.com/vpVD3.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/vpVD3.jpg" alt="enter image description here"></a></p>
  
  <p>That's also not nice, as it somehow truncates the last three subplots at the top and bottom.</p>
  
  <h2>3. Second, I use ggplot (inspired by <a href="http://mhairihmcneill.com/blog/2016/04/05/wordclouds-in-ggplot.html" rel="noreferrer">this</a>):</h2>
  
  <pre><code>library(ggplot2)
  library(ggrepel)
  
  df %&gt;%
    filter(book %in% c("Sense &amp; Sensibility", "Pride &amp; Prejudice",
                       "Mansfield Park", "Emma")) %&gt;%
    ggplot(., aes(x = 1, y = 1, size = n, label = word)) +
    geom_text_repel(segment.size = 0, segment.alpha = 0) +
    scale_size(range = c(2, 15), guide = FALSE) +
    theme_void() +
    theme(panel.border = element_rect(colour = "black", fill=NA, size=1)) +
    facet_wrap(~book) +
    labs(title = "Jane Austen Word Clouds")
  ggsave("jane_austen_gg.png", width = 11, height = 11)
  </code></pre>
  
  <p>Which creates:
  <a href="https://i.stack.imgur.com/aSSSK.png" rel="noreferrer"><img src="https://i.stack.imgur.com/aSSSK.png" alt="enter image description here"></a></p>
  
  <p>That looks strangely drawn out along the diagonal. And <code>wordcloud</code> looks better as it also orients some of the words vertically.</p>
  
  <p>Might there not be a way to insert the pretty <code>wordcloud</code> figures into ggplot?</p>