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.

Trial Inspector 1 Results Inspector 2 Results Average Results
Min. 1.00 100.0 106.0 103.0
1st Qu. 8.25 126.0 125.0 126.5
Median 15.50 129.0 130.5 129.2
Mean 15.50 130.7 131.5 131.1
3rd Qu. 22.75 135.2 136.5 136.6
Max. 30.00 147.0 146.0 146.5

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.