Get startedGet started for free

Use prebuilt color palettes

In celebration of your text mining skills, you may have had too many glasses of chardonnay while listening to Marvin Gaye. So if you find yourself unable to pick colors on your own, you can use the viridisLite package. viridisLite color schemes are perceptually-uniform, both in regular form and when converted to black-and-white. The colors are also designed to be perceived by readers with color blindness.

There are multiple color palettes, each with a convenience function. Simply specify n to select the number of colors needed.

magma(n = 3)
plasma(n = 5)
inferno(n = 6)

Each function returns a vector of hexadecimal colors based on n. Here's an example used with wordcloud:

color_pal <- cividis(n = 7)
wordcloud(chardonnay_freqs$term, chardonnay_freqs$num, max.words = 100, colors = color_pal)

This exercise is part of the course

Text Mining with Bag-of-Words in R

View Course

Exercise instructions

  • Use cividis() to select 5 colors in an object called color_pal.
  • Review the hexadecimal colors by printing color_pal to your console.
  • Create a wordcloud() from the chardonnay_freqs term and num columns. Include the top 100 terms using max.words, and set the colors to your palette, color_pal.

Hands-on interactive exercise

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

# Select 5 colors 
___ <- ___(___)

# Examine the palette output
___

# Create a word cloud with the selected palette
___(___)
Edit and Run Code