Home > analytics > Presidents in Twitter

Presidents in Twitter


I saw the release of a new version of twitteR package a few weeks back and thought I should be testing the code I wrote some time ago but also do something interesting at the same time. Thus I came up with the idea of checking out how Presidents are doing in twitter.

Not many Presidents are on twitter yet so my sample is fairly small. Here is my list:

  • @dilmabr (Brazil)
  • @CFKArgentina (Argentina –  I think you could have guessed it from the nick name, anyway)
  • @JuanManSantos (Colombia)
  • @chavezcandanga (Venezuela)
  • @sebastianpinera (Chile)
  • @BARACKOBAMA (USA)
  • @Number10gov (UK)

My idea was just to plot the number of followers by president but also the size of the point will be their number of tweets (statuses).

It is interesting to see the above, I’d have put David Cameron in second place not Hugo Chavez and trying to answer the “why” of this brings up a lot more questions like:

  • How much time Presidents have been in twitter?
  • How They use it?
  • How people in each country use Twitter?
  • population matters?

Anyway, for those of you interested in the code here it is:

library(twitteR)
library(ggplot2)
base <- NULL
lkuplist <- c('dilmabr','CFKArgentina','JuanManSantos','chavezcandanga','sebastianpinera',
              'BARACKOBAMA','Number10gov')

for(users in lkuplist){
  user <- getUser(users)
  userName <- screenName(user)
  followers <- followersCount(user)
  friends <- friendsCount(user)
  statuses <- statusesCount(user)
  # if the merged dataframe does not exist then create it
  if(!exists("base")){

    base <- as.data.frame(cbind(user=userName,followers=followers,friends=friends,statuses=statuses)
                          ,stringsAsFactors=F)
  }
  # if the merged dataframe exists, append new file to it
  if(exists("base")){
    temp <- as.data.frame(cbind(user=userName,followers=followers,friends=friends,statuses=statuses)
                          ,stringsAsFactors=F)
    base <- rbind(base,temp)
    rm(temp)
  }

}
# convert char to numbers
base <- transform(base, followers = as.numeric(followers),
                friends = as.numeric(friends),
                statuses = as.numeric(statuses))
# reorder variables
base  <- transform(base,user = reorder(user, followers))

p <- ggplot(base,aes(x=user,y=followers,color=statuses)) + geom_point(aes(size=statuses))
p <- p +scale_color_gradient() + coord_flip()
p <- p+scale_y_continuous(formatter = "comma",breaks=c(1000000,2500000,5000000,10000000))
p
About these ads
Categories: analytics Tags: , ,
  1. Ron M
    February 20, 2012 at 3:59 pm

    This is excellent. Thanks. I substituted the 30 stock symbols for the Dow Jones Industrial Index . Works great. link to plot – http://dl.dropbox.com/u/5568647/twitter%20dow%2030.jpg

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: