Plotting Data with R and rCharts

This semester, I’m taking a course that encourages using R for statistical analysis. I decided to see what I could do with it.

To get started, I installed R using homebrew started looking in to what sort of packages I could find and stumbled across rCharts.

rCharts “is an R package to create, customize and publish interactive javascript visualizations from R using a familiar lattice style plotting interface.”

“You can install rCharts from github using the dev tools package

install_github('rCharts', 'ramnathv’)

Once you have rCharts installed, you can create plot your data in nice looking javascript charts.

I saved all of the data from an in-class exercise to a csv. Here are the contents of that file:

trial,inspector 1 results, inspector 2 results, avg results

The following script reads the data from the csv file and plots it on a chart (I saved this as launchdata.r)

#!/usr/bin/env Rscript

#load rCharts

#assign contents of csv to variable: results
results <- read.csv("results.csv")

#plot data on graph
      parseTime = FALSE,
      data = launchdata,
      labels=list('Average', 'Inspector 2', 'Inspector 3'),

#print summary to console just for fun
print( summary(launchdata) )

Now I can run the script: source("launchdata.r”) from the R console which will open a nice interactive javascript line chart (below) in my browser and print a summary of all the data to the console.

 TrialInspector 1 ResultsInspector 2 ResultsAverage Results
1st Qu.8.25126.0125.0126.5
3rd Qu.22.75135.2136.5136.6

That’s about it.

This was mostly just an exercise in getting to know R; the data here isn’t very useful or interesting but the chart turned out pretty nice.

Note: The mPlot rCharts function used in this example uses the morris.js library to plot charts. According to a friend, morris isn’t being as actively maintained as some alternatives so it might be better to use one of those if possible. Fortunately, rCharts supports a number of js chart libraries out of the box.