2016-12-01 14 views
0

Ich arbeite an Wordcloud in R und bis jetzt bin ich erfolgreich mit nur den grundlegenden Sachen, aber was ich tun will, ist ich möchte Wortwolke von bestimmten Ort zeigen. Zum Beispiel, wenn ich Text wieWordcloud einer Spalte in R basierend auf einer anderen Spalte

     TEXT                 LOCATION 
    True or false? link(#Addition, #Classification)           NewYork,USA 
    Gene deFuser: detecting gene fusion events from protein sequences #bmC#bioinformatics Norwich,UK 
    Biologists do have a sense of humor, especially computational bio people     France 
    Semantic Inference using #Chemogenomics Data for Drug Discovery       London,UK 

hier die grundlegenden Wordcloud-Code ist ich benutze

library(tm) 
library(SnowballC) 
library(wordcloud) 

DATA<-c('True or false? link(#Addition, #Classification) ','Gene deFuser: detecting gene fusion events from protein sequences #bmC#bioinformatics',' Biologists do have a sense of humor, especially computational bio people','Semantic Inference using #Chemogenomics Data for Drug Discovery') 
Location<-c('NewYork,USA','Norwich,UK',' France','London,UK') 

jeopQ<-data.frame(DATA,Location) 

jeopCorpus <- Corpus(VectorSource(jeopQ$DATA)) 
jeopCorpus <- tm_map(jeopCorpus, content_transformer(tolower)) 

jeopCorpus <- tm_map(jeopCorpus, removePunctuation) 
jeopCorpus <- tm_map(jeopCorpus, PlainTextDocument) 
jeopCorpus <- tm_map(jeopCorpus, removeNumbers) 
jeopCorpus <- tm_map(jeopCorpus, removeWords, stopwords('english')) 
jeopCorpus <- tm_map(jeopCorpus, stemDocument) 
myDTM = TermDocumentMatrix(jeopCorpus, control = list(minWordLength = 1)) 

m = as.matrix(myDTM) 

v = sort(rowSums(m), decreasing = TRUE) 
set.seed(4363) 
wordcloud(names(v), v,max.words =100,min.freq=3,scale=c(4,0.1), random.order = FALSE,rot.per=.5,vfont=c("sans serif","plain"),colors=palette()) 

Ich möchte etwas wie eine eigene Wort-Wolke für Location „USA“ in ihm und Plätzen "mit UK "und eine separate Wordcloud für FRANKREICH, ist das möglich?

Antwort

0
jeopQ<-data.frame(DATA,Location) 

# Clean Location 
jeopQ$Location <- sub('.*,\\s*','', jeopQ$Location) 

# Loop 
for(i in unique(jeopQ$Location)){ 
    jeopCorpus <- Corpus(VectorSource(jeopQ$DATA[jeopQ$Location==i])) 
    jeopCorpus <- tm_map(jeopCorpus, content_transformer(tolower)) 

    jeopCorpus <- tm_map(jeopCorpus, removePunctuation) 
    jeopCorpus <- tm_map(jeopCorpus, PlainTextDocument) 
    jeopCorpus <- tm_map(jeopCorpus, removeNumbers) 
    jeopCorpus <- tm_map(jeopCorpus, removeWords, stopwords('english')) 
    jeopCorpus <- tm_map(jeopCorpus, stemDocument) 
    myDTM = TermDocumentMatrix(jeopCorpus, control = list(minWordLength = 1)) 

    m = as.matrix(myDTM) 

    v = sort(rowSums(m), decreasing = TRUE) 
    set.seed(4363) 
    wordcloud(names(v), v,max.words =100,min.freq=3,scale=c(4,0.1), random.order = FALSE,rot.per=.5,vfont=c("sans serif","plain"),colors=palette()) 

} 

enter image description here enter image description here enter image description here

+1

Das ist einfach perfekt! Vielen Dank! – hyeri

+0

@hyeri Glücklich zu helfen –

Verwandte Themen