Interactive visualizations with R

Hi Everyone,

In this blog am talking about the interactive visualization in R. We all knew that, the ever increasing volume of data in today’s world and it is impossible to tell stories without these visualizations. While there are dedicated tools like Tableau and QlikView, nothing can replace a modeling / statistics tools with good visualization capability. It helps tremendously in doing any exploratory data analysis as well as feature engineering. This is where R offers incredible help.

Interactive visualization allows deeper exploration of data than static plots. The most common interactive visualization packages in R with simple example plots. Here are the packages included:

  • ggplot2 – one of the best static visualization packages in RG
  • ggvis – interactive plots from the makers of ggplot2
  • rCharts – R interface to multiple javascript charting libraries
  • plotly – convert ggplot2 figures to interactive plots easily
  • googleVis – use Google Chart Tools from R
  • Shiny- one of the best interactive visualization packages in R.

Technical Features

Also other libraries for creating interactive visualizations from R do exist, such as clickme, RIGHT, ggobi, iplots, gg2v, rVega, cranvas and r2d3. Javascript libraries such as d3 have made possible wonderful new ways to show data. The d3Network package is also worth checking if you need cool interactive network visualizations.

technical-services

RCharts uses several javascript libraries and also the syntax used varies between different types of charts. All other packages than googleVis are clearly in an early development phase, which is visible in a limited features and documentation. As an experienced ggplot2 user it was often hard to adapt to the much narrower range of features included in ggvis.

Ggvis and googleVis seem to be the most advanced. rCharts especially suffers from the combination of multiple plot types with practically no documentation. So producing anything else than what’s provided in the existing examples was very hard. googleVis, sets itself apart by requiring the data in a different format than the other packages.

two 3d humans keep gears in hands

Plotly, is an interesting alternative to the other packages in that it simply takes as input a ggplot2 object and transforms it into an interactive chart that can then be embedded into websites. Using the service requires authentication, which is a clear limitation. By default all plots are made publicly visible to anyone, but there apparently is a way to produce private plots as well, with a limit in their number in the free account.

ggvis, is currently the only one of these packages that cannot produce map visualizations, but I hope this feature will be added in the future. Plotly can use maps created with ggplot2, but not yet with the handy ggmap extension.

Shiny, Makes it incredibly easy to build interactive web applications with R. Automatic “reactive” binding between inputs and outputs and extensive pre-built widgets make it possible to build beautiful, responsive, and powerful applications with minimal effort. A highly customizable slider widget with built-in support for animation. Pre-built output widgets for displaying plots, tables, and printed output of R objects.

Sharing the visualizations

Interactive visualizations are typically meant to be shared for a larger audience. Common ways to share interactive visualizations from R are as standalone html files, embedded in R markdown documents, and embedded in Shiny applications. All the studied packages can produce standalone htmls, though possibly with some loss of interactivity. Build useful web applications with only a few lines of code—no JavaScript required.

Example visualizations

PLOTLY

z1

set.seed(100)
d <- diamonds[sample(nrow(diamonds), 1000), ]
plot_ly(d, x = carat, y = price, text = paste(“Clarity: “, clarity),
mode = “markers”, color = carat, size = carat

 Scatterplot graph

z2

mtcars <- mtcars[order(mtcars$disp), ]
p <- plot_ly(mtcars, x = disp, y = mpg, mode = “markers”,
        text = rownames(mtcars), showlegend = FALSE)
add_trace(p, y = fitted(loess(mpg ~ disp)), mode = “lines”,
name = “loess smoother”, showlegend = TRUE)

Shiny

z3

z4

ggplot2 : ggplot(diamonds, aes(x=carat, y=price, color=color)) + geom_point()

z5

Summary

In general, being able to produce valid interactive html charts from R markdown. All of the packages great sensible outputs, but there are also a lot of differences. It’s easy to learn and work with plotly, ggplot2 and ggvis, as it pays attention to graphical details following the grammar of graphics principles. However, the package is still missing a lot of important features, such as faceting. In many cases rCharts can do what ggvis cannot (yet), and so it is a good alternative. Plotly has a really nice idea and implementation, but requirement for authentication and limited number of private plots reduce the usability a lot. Google’s Motion charts are cool and useful, but otherwise the input data format logic that differs from the packages makes using the package too hard in practice.

Pencil Mascot

 

 

 

 

 

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s