0

我想用这个wordcloud包创建一个 wordcloud。我的问题是我想在单词的开头保留大写,但所有字母都会自动转换为小写。

据我所知,当我使用该TermDocumentMatrix功能时会发生这种情况。是否有可能阻止该函数将所有字母转换为小写?

4

1 回答 1

0

您可以通过在控制列表中TermDocumentMatrix指定来防止将所有内容转换为小写。tolower=FALSE由于您没有提供任何数据,我将使用 tm 包中提供的示例数据进行说明。

library(wordcloud)
library(tm)
data(crude)

tdm = TermDocumentMatrix(crude, 
    control=list(removePunctuation=T, tolower=F, stopwords=T))
WordFreq = slam::row_sums(tdm[tdm$dimnames$Terms, ])
FrequentWords = tail(sort(WordFreq), 20)
wordcloud(names(FrequentWords), FrequentWords)

词云

于 2020-05-08T17:43:42.493 回答