I have just started with text mining and I am trying to get through Twitter Api the tweets that are Trending topic in Liverpool now, and represent them in a wordcloud.
But when getting trendings with getTrends
function from twitteR
library, I am unable to find anything that corresponds to the number of mentions that trending topic has. I want this number because I want to order the trendings by their number of mentions in order to represent them correctly on the wordcloud.
The code:
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"))
Maybe a possible way to do this is, one trending topics are obtained, if they are ordered, enumerate them (appending a column) and use that as the terms frecuency, but guess there must be a better way although I found nothing in the documentation