我想用wordcloud
包创建一个wordcloud。我的问题是我想在单词的开头保留大写字母,但是所有字母都会自动转换为小写字母。
据我所知,这是在使用TermDocumentMatrix
功能时发生的。是否有可能防止该函数将所有字母都转换为小写?
通过在控制列表中指定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)