Get Started

Improve word cloud colors

So far, you have specified only a single hexadecimal color to make your word clouds. You can easily improve the appearance of a word cloud. Instead of the #AD1DA5 in the code below, you can specify a vector of colors to make certain words stand out or to fit an existing color scheme.

wordcloud(chardonnay_freqs$term, 
          chardonnay_freqs$num, 
          max.words = 100, 
          colors = "#AD1DA5")

To change the colors argument of the wordcloud() function, you can use a vector of named colors like c("chartreuse", "cornflowerblue", "darkorange"). The function colors() will list all 657 named colors. You can also use this PDF as a reference.

In this exercise you will use "grey80", "darkgoldenrod1", and "tomato" as colors. This is a good starting palette to highlight terms because "tomato" stands out more than "grey80". It is a best practice to start with three colors, each with increasing vibrancy. Doing so will naturally divide the term frequency into "low", "medium", and "high" for easier viewing.

This is a part of the course

“Text Mining with Bag-of-Words in R”

View Course

Exercise instructions

  • Call thecolors() function to list all basic colors.
  • Create a wordcloud() using the predefined chardonnay_freqs with the colors "grey80", "darkgoldenrod1", and "tomato". Include the top 100 terms using max.words.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Print the list of colors
___

# Print the word cloud with the specified colors
___(___, ___,
    ___,
    ___)

This exercise is part of the course

Text Mining with Bag-of-Words in R

IntermediateSkill Level
5.0+
7 reviews

Learn the bag of words technique for text mining with R.

This chapter will teach you how to visualize text data in a way that's both informative and engaging.

Exercise 1: Common text mining visualsExercise 2: Test your understanding of text miningExercise 3: Frequent terms with tmExercise 4: Frequent terms with qdapExercise 5: Intro to word cloudsExercise 6: A simple word cloudExercise 7: Stop words and word cloudsExercise 8: Plot the better word cloudExercise 9: Improve word cloud colors
Exercise 10: Use prebuilt color palettesExercise 11: Other word clouds and word networksExercise 12: Find common wordsExercise 13: Visualize common wordsExercise 14: Visualize dissimilar wordsExercise 15: Polarized tag cloudExercise 16: Visualize word networksExercise 17: Teaser: simple word clustering

What is DataCamp?

Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.

Start Learning for Free