Interactive charts with rCharts

February 15, 2014
By

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

I have a few upcoming presentations as a part of job interviews. To prepare for these interviews, I'm attempting to make my figures a bit more interactive within my presentations. The aim is to be able to limit any large cumbersome tables I would need to include in my presentations and replace them with interactive plots that can look up values, zoom in, etc.

I initially explored both plot.ly and rCharts, but ended up using rCharts as I found I was more easily able to put it directly into my presentation. It may be possible with plot.ly but I did not want to put in the time to figure it out. I could only find a way to link to the website for the interactive version.

Using highcharts.js that is integrated into rCharts I was able to create the following interactive figure that explores the convergence rate of a portion of my dissertation.

library(rCharts)

h1 <- hPlot(x = "GenSerCor", y = "percent", group = "FitSerCor", data = converge)
h1$yAxis(title = list(text = "Convergence Rate"), min = 0, max = 100, tickInterval = 10)
h1$xAxis(title = list(text = "Generated Serial Correlation Structure"),
         categories = c("Ind", "AR1", "MA1", "MA2", "ARMA"))
h1$legend(verticalAlign = "top", align = "right", layout = "vertical", title = list(text = "Fitted SC"))
h1$plotOptions(series = list(lineWidth = 4))
h1$print('chart1', include_assets = TRUE, cdn = TRUE)

I edited the javascript manually to get some of the effects that I was looking for. For example, the differing line styles and adding the ability to zoom. It is possible to add this directly through rCharts, however I found it much more cumbersome compared to editing the effects I wanted manually. I find the rCharts framework is nice to give the user the barebones needed to produce an interactive plot that can be put into an HTML slideshow. Once getting the general structure, it is easy to look at the documentation for the javascript library and customize the plot yourself. I personally use slidy for that aspect and that is where I will use plots like this in the future. Creating these plots has also helped me to start learning some basics of Javascript which has been on my wish list for the last year or so.

To leave a comment for the author, please follow the link and comment on his blog: Educate-R - R.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: 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...

Comments are closed.