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
- 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.
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.
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
d <- diamonds[sample(nrow(diamonds), 1000), ]
plot_ly(d, x = carat, y = price, text = paste(“Clarity: “, clarity),
mode = “markers”, color = carat, size = carat
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)
ggplot2 : ggplot(diamonds, aes(x=carat, y=price, color=color)) + geom_point()
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.