Interactive plotting systems

The base, lattice, or ggplot2 plotting systems make it possible to create all conceivable plot types, either quick and simple, or even utterly detailed and sophisticated. All these systems have their own features and peculiarities. But they also have one thing in common: the relevant plots are all purely static.

In particular, the ubiquitous use of the Internet and corresponding browsers make it possible to easily share interactive content. Interactivity, in turn, helps humans to better understand the contents by actively interacting with them. Interactive charts are, of course, a great improvement, since viewers can play with the displayed data, and thus discover possible coherences and differences among other things to get a better understanding of the shown plot.

ggvis is practically the next evolutionary step forward from the successful data visualization package, ggplot2. Hadley Wickham (who is already the author of the ggplot2 package) and Winston Chang authored ggvis. The package description is as follows:

 

The goal is to combine the best of R (for example, every modeling function you can imagine) and the best of the web (everyone has a web browser). Data manipulation and transformation are done in R, and the graphics are rendered in a web browser using Vega. For RStudio users, ggvis graphics display in a viewer panel, which is possible because RStudio is a web browser.

 
 --Hadley Wickham, Winston Chang (http://ggvis.rstudio.com)

So, the ggvis package uses the grammar of graphics theory, which is already known from ggplot2, and uses the rendering of the popular JavaScript package, vega. Furthermore, it takes advantage of a few R packages. The reactive programming model of Shiny, the pipe operator (%>%) of the magrittr package, and the data transformation grammar of the dplyr package are all integrated into ggvis. Thus, the package uses a variety of different technologies to achieve a modern and interactive plotting system.

 

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

 
 --Ramnath Vaidyanathan (http://rcharts.io/)

As indicated in this quote, the rCharts package can virtually be considered as an interactive successor to the lattice plotting system. Since rCharts is not on CRAN, you need to install this package with a package called devtools directly from the GitHub repository of the package creator, Ramnath Vaidyanathan:

The following lines of code produce an interactive bar chart:

A look at the rCharts package

This bar chart is completely interactive. First, you can set the displayed bars as stacked or grouped. In the example, the stacked version is shown. Second, you can virtually switch on and off the eye colors. We switched the color green off; therefore it is not shown in the chart. Furthermore, you can hover over the bars to get the values of the plotted data.

The googleVis package can be downloaded directly from CRAN. By using the Google Charts API, a variety of different types of charts in a familiar look and feel are available. One limitation, as compared other packages, is certainly the mandatory Internet connection needed to display the chart outputs.

The following code produces an interactive bar and line chart combination:

The plot function call immediately opens a new browser window and displays the chart there:

Using googleVis

Here, interactivity is given by the fact that you can hover over the data, in this case the bars and the line, to know the exact values.

The htmlwidgets package is a relatively new approach to provide R users with multiple ways to display data and related stories around data, mostly in an interactive manner. In its core, it provides a framework for creating R bindings to JavaScript libraries. That means there are different R packages that are based on the htmlwidgets package. One main advantage of this package, for our purposes, is that the interactive charts can seamlessly be embedded within R Markdown. You install it along with the included packages mostly directly from CRAN. Some packages must be installed from GitHub.