r - Wordcloud 正在裁剪文本

标签 r text-analysis word-cloud sttwitterapi

我正在使用 twitter API 来产生情绪。我正在尝试根据推文生成词云。

这是我生成 wordcloud 的代码

wordcloud(clean.tweets, random.order=F,max.words=80, col=rainbow(50), scale=c(3.5,1))

结果:

enter image description here

我也试过这个:
pal <- brewer.pal(8,"Dark2")

wordcloud(clean.tweets,min.freq = 125,max.words = Inf,random.order  = TRUE,colors = pal)

结果:

enter image description here

我错过了什么吗?

这就是我获取和清理推文的方式:
#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)

提前致谢!

最佳答案

尝试将 wordcloud 上的比例从 c(3.5,1) 更改为 c(3.5,0.25)。

wordcloud(clean.tweets, random.order=F,max.words=80, col=rainbow(50), scale=c(3.5,0.25))

关于r - Wordcloud 正在裁剪文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47524602/

相关文章:

python - 如何对项目 :value list using another list with just items? 进行子集化

html - R rvest html 抓取

r - 使用 setMethod 为对象类型列表创建方法

r - 如何在 R 中创建允许类似向量索引的 S4 类?

css - 更改默认 CSS 类

c++ - 安装 Open GRM thrax 时出错

python - 确定句子的主题

Python 词云图周围没有任何空格

r - 将术语文档矩阵转换为 R 中的节点/边缘列表

python - 如何创建多次使用相同单词但颜色不同的词云?