6
트위터 API를 사용하여 감정을 생성하고 있습니다. 트윗을 기반으로 단어 구름을 생성하려고합니다. 이것에 대한Wordcloud가 텍스트 자르기입니다.
pal <- brewer.pal(8,"Dark2")
wordcloud(clean.tweets,min.freq = 125,max.words = Inf,random.order = TRUE,colors = pal)
결과 :
나는 또한이 시도: 여기
는 구름,이에 대한wordcloud(clean.tweets, random.order=F,max.words=80, col=rainbow(50), scale=c(3.5,1))
결과를 생성하는 내 코드입니다
나는 뭔가가 부족합니까?
이 내가 점점 트윗을 청소하고 방법입니다 사전에
#downloading tweets
tweets <- searchTwitter("#hanshtag",n = 5000, lang = "en",resultType = "recent")
# removing re tweets
no_retweets <- strip_retweets(tweets , strip_manual = TRUE)
#converts to data frame
df <- do.call("rbind", lapply(no_retweets , as.data.frame))
#remove odd characters
df$text <- sapply(df$text,function(row) iconv(row, "latin1", "ASCII", sub="")) #remove emoticon
df$text = gsub("(f|ht)tp(s?)://(.*)[.][a-z]+", "", df$text) #remove URL
sample <- df$text
# Cleaning Tweets
sum_txt1 <- gsub("(RT|via)((?:\\b\\w*@\\w+)+)","",sample)
sum_txt2 <- gsub("http[^[:blank:]]+","",sum_txt1)
sum_tx3 <- gsub("@\\w+","",sum_txt2)
sum_tx4 <- gsub("[[:punct:]]"," ", sum_tx3)
sum_tex5 <- gsub("[^[:alnum:]]", " ", sum_tx4)
sum_tx6 <- gsub("RT ","", sum_tex5)
# WordCloud
# data frame is not good for text convert it corpus
corpus <- Corpus(VectorSource(sum_tx6))
clean.tweets<- tm_map(corpus , content_transformer(tolower)) #converting everything to lower cases
clean.tweets<- tm_map(guj_clean,removeWords, stopwords("english")) #stopword are words like of, the, a, as..
clean.tweets<- tm_map(guj_clean, removeNumbers)
clean.tweets<- tm_map(guj_clean, stripWhitespace)
감사합니다!
clean.tweet 개체를 만드는 데 사용한 코드를 공유 할 수 있습니까? 나는 내 컴퓨터에 wordcloud를 생성하는 pblm이 없습니다. 'par()'옵션을 지정했을 가능성이 있습니까? –
@ColinFAY 업데이트 된 질문을 확인하십시오. 내 코드에서 par()를 사용하지 않습니다. –