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.
Installation:
You can install rCharts from github using the devtools package.
Create:
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.
Customize:
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.
Publish:
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:
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
Fill in the details to know more
Important Artificial Intelligence Tools
October 31, 2022
Top 28 Data Analytics Tools For Data Analysts | UNext
September 27, 2022
Stringi Package in R
May 5, 2022
Best Frameworks In Java You Should Know In 2021
May 5, 2021
Lean Management Tools: An Ultimate Overview For 2021
May 4, 2021
Talend ETL: An Interesting Guide In 4 Points
Add your details:
By proceeding, you agree to our privacy policy and also agree to receive information from UNext through WhatsApp & other means of communication.
Upgrade your inbox with our curated newletters once every month. We appreciate your support and will make sure to keep your subscription worthwhile