開始使用免費開始

強化文字雲的配色

到目前為止,你只用了一種十六進位色碼來產生文字雲。你可以很容易讓文字雲看起來更好。把下面程式中的 #AD1DA5 改成一個顏色向量,就能讓特定詞彙更突出,或符合既有的配色方案。

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

若要更改 wordcloud()colors 參數,可以使用具名顏色的向量,例如 c("chartreuse", "cornflowerblue", "darkorange")colors() 函式會列出全部 657 種具名顏色。你也可以參考這份 PDF

在這個練習中,你會使用「grey80」、「darkgoldenrod1」和「tomato」作為顏色。這組配色很適合用來突顯詞彙,因為「tomato」比「grey80」更醒目。最佳做法是先從 3 種顏色開始,並讓飽和度依序提高。這樣可以自然地把詞頻分成「低」、「中」、「高」,更容易閱讀。

本練習屬於課程

R 的 Bag-of-Words 文本探勘

檢視課程

練習說明

  • 呼叫 colors() 函式以列出所有基本顏色。
  • 使用預先定義的 chardonnay_freqs 建立一個 wordcloud(),配色為「grey80」、「darkgoldenrod1」與「tomato」,並以 max.words 納入前 100 個詞。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Print the list of colors
___

# Print the word cloud with the specified colors
___(___, ___,
    ___,
    ___)
編輯並執行程式碼