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)
이 연습은 강의의 일부입니다
Text Mining with Bag-of-Words in R
연습 안내
- Use
cividis()to select5colors in an object calledcolor_pal. - Review the hexadecimal colors by printing
color_palto your console. - Create a
wordcloud()from thechardonnay_freqstermandnumcolumns. Include the top 100 terms usingmax.words, and set thecolorsto your palette,color_pal.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Select 5 colors
___ <- ___(___)
# Examine the palette output
___
# Create a word cloud with the selected palette
___(___)