Aan de slagGa gratis aan de slag

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)

Deze oefening maakt deel uit van de cursus

Text Mining with Bag-of-Words in R

Cursus bekijken

Oefeninstructies

  • 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.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Select 5 colors 
___ <- ___(___)

# Examine the palette output
___

# Create a word cloud with the selected palette
___(___)
Code bewerken en uitvoeren