Analysis of devices used to post on Twitter – R code

Hi Everybody,

After collecting twitter data (JULIANHI), then interesting analysis can be done on the devices used to tweets

df = searchTwitter("@Nissan_India")

Now Analyzing the Source data

Now cleaning the source data

d <- df$source
    d <- gsub("  ", " ", d)
    d <- gsub("Twitter for", "", d)
    d <- gsub("</a>", "", d)
    d <- strsplit(d, ">")
    d <- sapply(d, function(x) ifelse(length(x) > 1, x[2], x[1]))
    t <- sort(table(d), decreasing=TRUE)
top<- 10 ##top 10 devices
if( top < length(t))
        t <- t[1:top]

library (arrayhelpers)

b1 <- array2df (t)
colnames (b1)<- c("Value", "Devices")

rr1<- sum(b1$Value) ###sum of devices mentioned 

Now plotting them using ggplot

library (ggplot2)
ce <- ddply(b1, "Devices", transform,percent_weight = Value / sum(b1$Value) * 100)
##plotting the devices
p1 <- ggplot (ce, aes (x=Devices, y=percent_weight, fill =Devices))+geom_bar(stat="identity")+ geom_text(aes(label=sprintf("%1.1f",percent_weight)), hjust=-0.05, colour="black", size=3)+coord_flip()+ ggtitle(paste("@Nissan_India: Sum of total devices=",rr1))

print (p1)

interesting output is what we get now

Device used for tweets


2 thoughts on “Analysis of devices used to post on Twitter – R code

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