Ну, как вы можете видеть здесь: Делайте все слова прописными в Wordcloud в R , когда вы делаете TermDocumentMatrix(CORPUS)
, по умолчанию слова получают строчные буквы.В самом деле, если вы делаете trace(wordcloud)
, когда нет аргумента freq
, выполняется tdm <- tm::TermDocumentMatrix(corpus)
, поэтому ваши слова идут в нижнем регистре.
У вас есть два варианта решения этой проблемы: включить слова и частоту вместо корпуса:
filePath <- "http://www.sthda.com/sthda/RDoc/example-files/martin-luther-king-i-have-a-dream-speech.txt" # I am using this text because you DID NOT PROVIDED A REPRODUCIBLE EXAMPLE
text <- readLines(filePath)
products <- Corpus(VectorSource(text))
products <- tm_map(products, toupper)
c_words <- brewer.pal(8, 'Set2')
tdm <- tm::TermDocumentMatrix(products, control = list(tolower = F))
freq_corpus <- slam::row_sums(tdm)
wordcloud(names(freq_corpus), freq_corpus, min.freq = 10, max.words = 30, scale = c(7,1), colors = c_words)
И вы получите:
Второй вариант - изменить wordcloud:
Сначала вы делаете trace(worcloud, edit=T)
, а затем заменяете строку 21 на:
tdm <- tm::TermDocumentMatrix(corpus, control = list(tolower = F))
Нажмите сохранить и выполнить:
filePath <- "http://www.sthda.com/sthda/RDoc/example-files/martin-luther-king-i-have-a-dream-speech.txt"
text <- readLines(filePath)
products <- Corpus(VectorSource(text))
products <- tm_map(products, toupper)
c_words <- brewer.pal(8, 'Set2')
wordcloud(names(freq_corpus), freq_corpus, min.freq = 10, max.words = 30, scale = c(7,1), colors = c_words)
Вы получите что-то вроде:
![enter image description here](https://i.stack.imgur.com/6Fmld.png)