2016-11-17 8 views
1

При создании 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) 

Это приводит к следующему выходу

enter image description here

ответ

3

Это потому, что за кулисами TermDocumentMatrix(clean_corp) делают TermDocumentMatrix(clean_corp, control = list(tolower = TRUE)). Если вы установите его на TermDocumentMatrix(clean_corp, control = list(tolower = FALSE)), то слова будут оставаться в верхнем регистре. Кроме того, вы также можете настроить имена строк вашей матрицы: rownames(data_m) <- toupper(rownames(data_m)).

+0

Спасибо, я прав, если учесть, что после уборки больше смысла, чем очистка, в частности удаление стоп-слов, принимать строчные буквы? – FilipW

+0

Таким образом, вы конвертируете в нижний регистр и затем конвертируете в верхний регистр. Поэтому я просто укажу контрольный аргумент. – lukeA

 Смежные вопросы

  • Нет связанных вопросов^_^