Your verification ID is: guDlT7MCuIOFFHSbB3jPFN5QLaQ Big Computing: An example a scatter plot using rChart to do the plot in R

Thursday, November 13, 2014

An example a scatter plot using rChart to do the plot in R

Recently at the Connecticut R Users Meetup Aaron Goldenberg gave a talk where he gave examples using rCharts to do plots in R. rCharts is one of a group of R packages that leverages javascript graphics libraries to make them available in an easy way for R users. R has great graphics capability within it, but that graphics capability is static and not interactive. Development in the last few years by some people have created a number of ways to address add that capability. rCharts is an example of one of the better javascript graphic libraries and RStudio’ shiny is a good example on making those graphics truely interactive. The combining of the two is produces powerful and engaging graphics, and I encourage anyone who is thinking about doing that to try it. The results are impressive and fairly easy to create.
I am going to do a few quick examples to get you started using this great package.
First, you will need to load the rCharts package. This is a little different because rCharts in not on CRAN, but it is on Github. In order to install packages from Github you will need to first install the package devtools from CRAN on your computer.
Now we have the ability to downlaod the rCharts package from Github.
Now we are ready to do some plots. Lets start with the old favorite mtcars Data set that comes with base R and do a simple scatter plot.
rPlot(mpg~wt, data=mtcars,type="point")

It looks just like a normal scatter plot in R, but not when you move the cursor over a point in the plot the data for that point pops up in a little box. this is so sweet. you can also make this scatter plot faceted
rPlot(mpg~wt|am, data=mtcars,type="point")

So now we have created two side by side graphs where the data is further divided by if the car is automatic or manual. We can further divide this data by making the colors of the points represent how many cylanders the cars has.
rPlot(mpg~wt|cyl, data=mtcars,color="cyl",type="point")

Pretty powerful stuff. In basically one line of code I am able to create an interactive scatter plot show four demsions of a data set!

I am sorry that the screenshot are a little weak, but I wanted to show how the hover function with the cursor works and that was the best I could do in the amount of time I had. I will try and do a better job in future posts.