词云正在裁剪文本。

13

我正在使用 Twitter API 生成情感分析,希望根据推文生成词云。

以下是我的代码以生成词云:

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

这是结果:

在这里输入图片描述

我也尝试了这个:

pal <- brewer.pal(8,"Dark2")

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

这是结果:

在此输入图片描述

我有遗漏吗?

以下是我获取和清理推文的方法:

#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对象所用的代码吗?我在我的电脑上生成词云没有问题。有没有可能在此之前指定了par()选项? - Colin FAY
@ColinFAY 请检查更新的问题。我的代码中没有使用par()函数。 - Harsh Shah
2个回答

2
裁剪似乎发生在历史记录中存在先前的图形时。我也遇到了这个问题,通过点击扫帚按钮清除绘图历史记录(单击链接查看图像),然后重新创建词云即可解决。 在此处查看图像

提供代码以准确展示您如何解决词云问题会非常有用。 - Shawn Hemelstrand
我没有用代码解决它,我使用了与先前答案相同的代码来生成词云,然后通过在R中清除绘图历史记录来修复裁剪问题,然后重新生成了词云。我添加了一个链接,显示我按下哪个按钮来修复裁剪。 - Robert Clark

1

尝试将您的词云图的比例从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))

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接