Weave Magic With Interactive Visualizations: Creating Polychart Using rCharts


In an earlier post we talked about How Upshot is Using Interactive Visualizations to Make Online News Fun and Interactive, with the objective of giving you an example of a real-time application of interactive visualizations. I also gave you a quick guide to the popular interactive data visualization tools. In this post I will outline how you can actually use one of the tools and create Polychart using rCharts, while also highlighting other alternatives to creating interactive visualizations with R.

Typically, creating interactive javascript visualizations with R often involves a three step process: create, customize and publish. You are going to see all these steps involved in creating polychart visualizations using a sample dataset. Firstly, I will mention the scripts needed to install rCharts on your R interface and then provide details on the three step process.


You can install rCharts from github using the devtools package.


rCharts uses a formula interface to specify plots, just like the lattice package. Polychart.js javascript library generally provides support for visualizations around scatter plots, line plots, bar plots, pie charts etc. In this tutorial, I will only showcase building a facetted scatter plot using Ploychart.js library with the help of rCharts in-built functions. rCharts supports multiple javascript charting libraries, each with its own strengths. Each of these libraries has multiple customization options, most of which are supported within rCharts.


The output of the html showcased above would be an interactive one when you see it on your system. Unfortunately, you won’t be able to view this visualization directly within R console as html scripts are not directly supported in the standard plots output interface. You can add some interactivity to this chart now using the below javascript code, and adding to the mtcars_scatter_plot.html source file which was created earlier. This code would return an output call of each data point whenever you click on one.

graph_chart1.addHandler(function(type, e){

var data = e.evtData;

if (type === ‘click’){

return alert(“You clicked on car with mpg: ” + data.mpg.in[0]);



Creating the plot was cool, as it was done completely in R, but when it comes to viewing and customizing it, it definitely is not straight forward as tweaking of html file with javascript code was required. This can be addressed with the help of R markdown coding and knitr package which would create beautiful html compiled R notebooks with your R console. You can refer to this video tutorial on how to do everything within your console without directly dealing with any html output.


You can publish your visualization as a standalone html page using the publish method. This approach is different from saving your plot as html file like mentioned earlier. With publish method; you have the option of viewing your html files online with the help of either your github or rpubs account.

r1$publish(‘Scatterplot’ , host = ‘gist’)

r1$publish(‘Scatterplot’ , host = ‘rpubs’)

For more examples on different kinds of interactive visualizations that can be created using rCharts, you can refer to this documentation compiled by Ramnath.

Other Alternatives:

Some of the other useful packages in R for creating interactive visualizations are:

  • ggvis– interactive plots from the makers of ggplot2
  • ly– convert ggplot2 figures to interactive plots easily
  • googleVis– use Google Chart Tools from R

Found this fascinating? Want to find out more about a career in Data Analytics? Visit Jigsaw Academy’s course pages and find the course that will take your career to greater heights.

Related Reads:

How Upshot is Using Interactive Visualizations to Make Online News Fun and Interactive

5 Popular Tools for Data Visualization

Related Articles

Please wait while your application is being created.
Request Callback