Creating word clouds in RStudio
A word cloud is very useful when we want to visualize the content of a text quickly. The more times a word is repeated within the text, the bigger it will be displayed on the word cloud, giving us a sense of what we can expect if we read the text. It is kind of a summary.
Once we have a dataset with words and their frequencies, plotting a word cloud takes just one line of code. The function is the same name as the library, wordcloud2()
, and it takes as inputs the dataset, a color palette or a vector of colors, and the size of the words:
# Generating WordCloud wordcloud2(data=word_freq, color="random-dark", size=1)
The result after running this code is printed as follows.
Figure 12.10 – Word cloud generated with the content from Chapter 10 of this book
Just to refresh our minds, Chapter 10 is about an introduction to the ggplot2
library. It brings the concepts of the grammar of graphics and introduces...