2016-11-17 3 views
1

Bei der Erstellung von Wordclouds ist es üblich, alle Wörter in Kleinbuchstaben zu schreiben. Ich möchte jedoch, dass die Wordclouds die Wörter Großbuchstaben anzeigen. Nachdem die Wörter groß geschrieben wurden, werden in der Wortwolke immer noch Kleinbuchstaben angezeigt. Irgendwelche Ideen warum?Machen Sie alle Wörter in Wordcloud großgeschrieben in

Reproduzierbare Code:

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) 

Dies erzeugt auf folgende Ausgabe

enter image description here

Antwort

3

Es ist, weil hinter den Kulissen TermDocumentMatrix(clean_corp) ist TermDocumentMatrix(clean_corp, control = list(tolower = TRUE)) tun. Wenn Sie es auf TermDocumentMatrix(clean_corp, control = list(tolower = FALSE)) festlegen, bleiben die Wörter in Großbuchstaben. Alternativ können Sie auch nachträglich die Zeilennamen Ihrer Matrix anpassen: rownames(data_m) <- toupper(rownames(data_m)).

+0

Danke, habe ich recht zu denken, dass es sinnvoller ist, die rownames nach der Reinigung zu verbessern, da die Reinigung, insbesondere das Entfernen von Stoppwörtern, Kleinbuchstaben annehmen? – FilipW

+0

Auf diese Weise würden Sie in Kleinbuchstaben konvertieren und anschließend in Großbuchstaben konvertieren. Also würde ich nur das Steuerelement Argument angeben. – lukeA