Which users are the most tweeting your product?
In this post I want to teach you how to see which users talk about something on Twitter and present it in a simple chart. For this example we are going to look at the hashtag #nintendo.
As we saw in another Post , the first thing we have what to do is make the query on Twitter and save it in a data frame.
library(twitteR)
api_key <- "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
api_secret <- "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
setup_twitter_oauth(api_key,api_secret)
## [1] "Using browser based authentication"
Query= searchTwitter("#Rstats", geo=NULL)
Result= twListToDF(Query)
We create the user variables, selecting the data frame users and order them from largest to smallest.
Users = table(Result$screenName)
Users_sort= sort(Users, decreasing=T)
To present this data in a visual way we create a color palette with a gradient.
degraded= function (color1, color2, degraded)
{
library(grDevices)
palete = colorRampPalette(c(color1, color2))
palete (degraded)
}
palette = degraded("#033240", "#0895BF", 15)
To be able to visualize this data we are going to create a graph, broken down into three parts: 1º We establish the margins to adjust the image 2º We draw the graph with the 15 most active users. 3º We add a legend explaining the data.
par(mar=c(10,5,2,2), bg="white")
barplot(Users_sort[1:15], las=2, cex.names =1, col=palette )
And we get a graphic representation of the users who most Tweet with the hashtag # Rstats.