Search code examples
rr-markdownword-cloudbeamer

Side by side wordclouds in R markdown


Trying to plot two WordClouds side by side for a Beamer presentation in R Markdown and I'm struggling to work out how to do it. I'm aware you can use grid.arrange() if you set the plots as objects but WordClouds cannot be set as object as far as I'm aware.

Many Thanks in Advance
Samuel


Solution

  • You may try par(mfrow=c(1,2)) from BASE R and do something like below, I have tested it on RStudio beamer as well, it works:

    library(wordcloud)
    par(mfrow=c(1,2))
    obj1 <- data.frame(words=c("a","b","c"),
                       freq=c(10,6,2))
    
    obj2 <- data.frame(words=c("a","b","c"),
                       freq=c(15,11,5))
    
    wordcloud(obj1$words, obj1$freq, min.freq =3, 
              scale=c(5, .2), random.order = FALSE, random.color = FALSE, 
              colors= c("red"))
    
    wordcloud(obj2$words, obj2$freq, min.freq =3, 
              scale=c(5, .2), random.order = FALSE, random.color = FALSE, 
              colors= c("green"))
    

    enter image description here