如何用 R 建立黑白詞雲?


根據 Google 的說法,詞雲是一種由特定文字或主題中使用的單片語成的影像,其中每個單詞的大小表示其頻率或重要性。在 R 中,我們可以使用 wordcloud 軟體包的 wordcloud 函式建立詞雲。因此,我們具有與該軟體包相同的函式名,因此我們不應該因此感到困惑。

載入 wordcloud 軟體包並建立詞雲 −

library("wordcloud")
x<-c("tutorialspoint is one of the best free resources for online learning")
wordcloud(x)

警告資訊 −

  • 在 tm_map.SimpleCorpus(corpus, tm::removePunctuation) 中 −

變換會刪除文件

  • 在 tm_map.SimpleCorpus(corpus, function(x) tm::removeWords(x, tm::stopwords())) 中 −

變換會刪除文件

輸出

讓我們來看另一個示例 −

y<-c("covid-19 has changed almost everything that happens around the world")
wordcloud(y)

警告資訊 −

  • 在 tm_map.SimpleCorpus(corpus, tm::removePunctuation) 中 −

變換會刪除文件

  • 在 tm_map.SimpleCorpus(corpus, function(x) tm::removeWords(x, tm::stopwords())) 中 −

變換會刪除文件

輸出

更新於: 14-Oct-2020

140 次瀏覽

開啟您的 職業

完成課程即可獲得認證

開始
廣告
© . All rights reserved.