При создании Wordclouds наиболее распространено делать все слова в нижнем регистре. Тем не менее, я хочу, чтобы wordclouds отображали слова в верхнем регистре. После того, как слова были заглавными, wordcloud все еще отображает строчные слова. Любые идеи почему?Сделать все слова в верхнем регистре в Wordcloud в R
воспроизводимый код:
library(tm)
library(wordcloud)
data <- data.frame(text = c("Creativity is the art of being ‘productive’ by using
the available resources in a skillful manner.
Scientifically speaking, creativity is part of
our consciousness and we can be creative –
if we know – ’what goes on in our mind during
the process of creation’.
Let us now look at 6 examples of creativity which blows the mind."))
text <- paste(data$text, collapse = " ")
# I am using toupper() to force the words to become uppercase.
text <- toupper(text)
source <- VectorSource(text)
corpus <- VCorpus(source, list(language = "en"))
# This is my function for cleaning the text
clean_corpus <- function(corpus){
corpus <- tm_map(corpus, removePunctuation)
corpus <- tm_map(corpus, removeNumbers)
corpus <- tm_map(corpus, stripWhitespace)
corpus <- tm_map(corpus, removeWords, c(stopwords("en")))
return(corpus)
}
clean_corp <- clean_corpus(corpus)
data_tdm <- TermDocumentMatrix(clean_corp)
data_m <- as.matrix(data_tdm)
commonality.cloud(data_m, colors = c("#224768", "#ffc000"), max.words = 50)
Это приводит к следующему выходу
Спасибо, я прав, если учесть, что после уборки больше смысла, чем очистка, в частности удаление стоп-слов, принимать строчные буквы? – FilipW
Таким образом, вы конвертируете в нижний регистр и затем конвертируете в верхний регистр. Поэтому я просто укажу контрольный аргумент. – lukeA