The Wordcloud2 library

A word cloud (or tag cloud) is a visual representation of text data. Tags are usually single words, and the importance of each tag is shown with font size or color. This mode of representation is useful for quickly perceiving the most prominent terms in a list and determine their relative prominences. In R, two libraries will allow you to create wordclouds: Wordcloud and Wordcloud2. In this post I will introduce the main features of the awesome Wordcloud2 library developed by Chiffon Lang.


This little tutorial is largely inspired from the well-done vignette of the package. Most of the credit goes to Chiffon Lang, but this package clearly feats in the gallery. In order to make our first tagcloud, we need to load the library which contains an example dataset.




As you can see, wordcloud2 takes a dataframe with 2 columns as input . The first column gives the words that will be displayed in the wordcloud, and the second column gives their relative prominences.

We start with the default wordcloud, without changing any argument. Simply adjust the size of the wordcloud using the size argument.

———————-196_wordcloud_ex2 196_wordcloud_ex3 196_wordcloud_ex4

Then, it is possible to change words and background colors with the color and backgroundColor arguments.

—————196_wordcloud_ex5 196_wordcloud_ex6

It is possible to change the shape of the wordcloud. Several shapes are available within the package: ‘circle’ (default), ‘cardioid’, ‘diamond’ (alias of square), ‘triangle-forward’, ‘triangle’, ‘pentagon’, and ‘star’).

It is also possible to use any image you have as a mask! Just insert the image in the current working directory and use it as in the code below.




Control the rotation of words with 3 arguments: minRotation, maxRotation and rotateRatio.




A nice chinese version

———–196_wordcloud_ex9 ——–196_wordcloud_ex10

The lettercloud function allows to use a letter or a word as a shape for the wordcloud.

Save wordcloud2 as PDF

Last but not least, let’s check how to save our wordcloud as a static .pdf image. Wordcloud2 is made from a html widget. It means your wordcloud will be output in a html format by default.

You can export it as a pdf image using rstudio, or using the webshot library as follow:

I hope these few lines of code will allow you to compute your wordclouds efficiently. You can find more wordcloud examples on the dedicated section of the R graph gallery. Of course, do not hesitate to share your charts with the gallery if you used specific features that were not described above. And once more, thank you to Chiffon Lang for creating such a useful library.

Happy ploting!

Not what you are looking for ? Make a new search !


8 thoughts on “The Wordcloud2 library

  1. I built wordcloud using wordcloud2 function in shiny app. In wordcloud, words are inserting in cloud but there is no sign which can show that wordcloud is completed. is there any way i can show that still words are being inserted

  2. I would like to thank the developer .Im currently using Wordcloud2 in my Data mining project.Visualizing each wordcloud in a mask of the country vector map.

  3. I’m unable to get the demoFreq sample words to appear over the bird image. Same with trying it for a word or a letter. I get the shape, but not the words from the data frame. Any ideas?

    I don’t have anything related to shiny installed. Is it necessary to do so?

    1. Hi Ross,
      Hard to know what’s going on without more detail.
      In any case, nothing related to shiny is necessary to use the Wordcloud2 library.


      1. Hi Holtz,

        I’m having the same problem as Ross. Same with using my own image as a background for the wordcloud.

        Could you help me out please?


Leave a Reply

Your email address will not be published.