Charting Wikipedia interest in GOP candidates with googleVis

[This article was first published on PremierSoccerStats » R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

I recently posted an article on how to collate Wikipedia page views

As there is a time component to this, it seemed appropriate to use the googleVis Package to visualize changes in page hits in the Google Motion chart

For this exercise, I ran the wikiFun function covered in the last post to collate page visits for the main Republican candidates for the Presidency. There are a couple of points worth mentioning so I have incorporated the relevant code

?View Code RSPLUS
 
library(googleVis)
 
# dataframe, GOPdata, has daily Wikipedia page views for leading candidates from beginning of 2011
 
# create and plot chart locally
myChart <- gvisMotionChart(GOPdata, idvar="name", timevar="date")
plot(myChart)
 
# set preferred initial state (e.g line rather than bubble chart etc.) then from
#Settings(the wrench) > Advanced > Advanced copy the state string to a variable
 
# enclose the copied string in single quotes exactly as below
initState <- ' 
  {"nonSelectedAlpha":0.4,"yZoomedDataMin":0,"yLambda":0,"yZoomedDataMax":600000,
   "xZoomedIn":false,"xZoomedDataMin":0,"yZoomedIn":false,"time":"2011","playDuration":15000,
   "orderedByY":false,"sizeOption":"_UNISIZE","iconKeySettings":[{"key":{"dim0":"Mitt Romney"}}],
   "xLambda":1,"colorOption":"_UNIQUE_COLOR","duration":{"multiplier":1,"timeUnit":"D"},
   "yAxisOption":"2","dimensions":{"iconDimensions":["dim0"]},"iconType":"VBAR",
   "uniColorForNonSelected":false,"orderedByX":true,"xZoomedDataMax":9,"showTrails":false,
   "xAxisOption":"2"}
'
 
# reproduce chart with
myChart <- gvisMotionChart(GOPdata, idvar="name", timevar="date", options=list(state=initState))
plot(myChart) 
 
# copy the chart html to a file
cat(myChart$html$chart, file="GOP2012.html")

The html can then be massaged as required and uploaded. I would normally post this on this blog but I had difficulties using the suggested custom fields plugin and , in any case, it would probably be too large. It can be viewed here

The graph reflects the changes in fortune of the participants quite well with eight different candidates having at least six days at the top. Now the election is nigh, however, Romney is outpacing his closest rival 10:1

To leave a comment for the author, please follow the link and comment on their blog: PremierSoccerStats » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.