Charting Wikipedia interest in GOP candidates with googleVis

October 29, 2012

(This article was first published on PremierSoccerStats » R, and kindly contributed to R-bloggers)

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

# 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")
# 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 <- ' 
   "orderedByY":false,"sizeOption":"_UNISIZE","iconKeySettings":[{"key":{"dim0":"Mitt Romney"}}],
# reproduce chart with
myChart <- gvisMotionChart(GOPdata, idvar="name", timevar="date", options=list(state=initState))
# 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. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Tags: ,

Comments are closed.

Search R-bloggers


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)