有没有办法从R中的推文中获取热门话题数量?

时间:2017-01-30 20:08:53

标签: r twitter text-mining trending

我刚刚开始使用文本挖掘,我正试图通过Twitter Api来获取利物浦现在的趋势主题的推文,并用wordcloud代表它们。

但是当从getTrends库获取具有twitteR函数的趋势时,我无法找到与趋势主题所提及的数量相对应的任何内容。我想要这个号码,因为我想通过提及的次数来命令趋势,以便在wordcloud上正确地表示它们。

代码:

library(twitteR)
library(wordcloud)

Locs=availableTrendLocations()
locsEngland=subset(Locs,country="United Kingdom")
id=subset(locsEngland,name=="Liverpool")
trends=getTrends(woeid = id)
trends=Corpus(VectorSource(trends$name))
trends=TermDocumentMatrix(trends)
ap.tdm=as.matrix(trends)
ap.v=sort(rowSums(ap.tdm),decreasing = T)
ap.d=data.frame(word=names(ap.v),freq=ap.v)

wordcloud(ap.d$word,ap.d$freq, scale=c(3,0.5), max.words=50, random.order=FALSE, rot.per=0.15, use.r.layout=FALSE, colors=brewer.pal(,"Dark2"))

也许一种可能的方法是,获得一个趋势主题,如果它们被排序,枚举它们(附加一列)并将其用作术语频率,但是猜测必须有更好的方法,尽管我什么都没发现在the documentation

0 个答案:

没有答案
相关问题