If you've visited the CRAN repository of R packages lately, you might have noticed that the number of available packages has now topped a dizzying 12,550. This means there are packages for practically any data visualization task you can imagine, from visualizing cancer genomes to graphing the action of a book.
For new R coders, or anyone looking to hone their R data viz chops, CRAN's repository may seem like an embarrassment of riches—there are so many data viz packages out there, it's hard to know where to start.
To provide one path through the labyrinth, today we’re giving an overview of 9 useful interdisciplinary R data visualization packages. We’ve noted the ones you can take for a spin without the hassle of running R locally, using Mode R Notebooks.
While it's relatively easy to create standard plots in R, if you need to make a custom plot, things can get hairy fast. That's why ggplot2 was born: to make building custom plots easier.
In the words of its creator, ggplot2 “takes care of many of the fiddly details that make plotting a hassle (like drawing legends) as well as providing a powerful model of graphics that makes it easy to produce complex multi-layered graphics.”
ggplot2 is based on The Grammar of Graphics, a system for understanding graphics as composed of various layers that together create a complete plot. With ggplot2, you can, for instance, start building your plot with axes, then add points, then a line, a confidence interval, and so on.
The drawback of ggplot2 is that it may be slower than base R, and new programmers may find the learning curve to be a bit steep. But fans argue that learning to master ggplot2 and (more generally) the tidyverse way of handling data pays huge dividends for any data scientist working in R.
Fitted models in panel functions (Deepayan Sarkar)
When you need to visualize multi-variate data, Lattice is your friend. Lattice is a system of plotting inspired by Trellis graphics. It helps you create tiled panels of plots to compare different values or subgroups of a given variable. (These tiled plots often end up looking like a garden trellis, as you can see above.)
Lattice was built using the grid package for its underlying implementation and it inherited a lot of grid's features. Since grid has subsequently been folded into base R, the logic of Lattice should feel familiar to many base R users.
For a deep dive into the differences between using ggplot2 and Lattice, check out this 12-part series over at Learn R.
Interactive heatmap (Joshua Kunst)
Highcharter makes dynamic charting easy. It uses a single function, hchart(), to draw plots for all kinds of R object classes, from data frame to dendrogram to phylo. It also gives R coders a handy way to access the other popular Highcharts plot types, Highstock (for financial charting) and Highmaps (for schematic maps in web-based projects).
The package has easy-to-customize themes, along with built-in themes like “economist,” “financial times,” and “538,” in case you want to borrow a look for your chart from the pros.
GeoJSON map (RStudio)
Leaflet offers a lightweight but powerful way to build interactive maps, which you've probably seen in action (in their JS form) on sites ranging from The New York Times and The Washington Post to GitHub and GIS specialists like Mapbox and CartoDB.
The R interface for Leaflet was developed using the htmlwidgets framework, which makes it easy to control and integrate Leaflet maps right in R Markdown documents (v2), RStudio, or Shiny apps.
ROYGB Scatter (ModernData)
RColorBrewer makes it easy to take advantage of one of R's great strengths: manipulating colors in plots, graphs, and maps.
The package is based on Cynthia Brewer’s work on the use of color in cartography (check out Colorbrewer to learn more), and it lets you create nice-looking sequential, diverging, or qualitative color palettes. It also plays nicely with Plotly, as these examples by Plotly demonstrate.
Line plot (Plotly)
You might know Plotly as an online platform for data visualization, but did you also know you can access its capabilities from an R or Python Notebook?
Sunburst chart of baseball pitch data (Kent Russell)
With SunburstR, you can build R charts just like the sunburst sequence visualizations created by Kerry Rodden in d3.js. The diagrams are interactive, giving viewers a powerful way to explore sequence data on their own.
3D plot of iris data in RGL (Duncan Murdoch)
To create interactive 3D plots in R, check out RGL. Its logic is loosely modeled after base R graphics, but in three dimensions rather than two. Like Lattice, it's inspired by the grid package (though it's not technically compatible with it), so its methods should feel familiar to seasoned R coders.
RGL has lots of cool bells and whistles, including a variety of 3D shapes to choose from, lighting effects, various “materials” for the objects, and even the ability to make an animation your 3D scene.
Time series chart with range selector (RStudio)
But dygraph's interactivity doesn't come at the expense of speed: it can handle huge datasets with millions of points without slowing its roll. And you can use RColorBrewer with dygraphs to choose a different color palette for your time series— check out this example to see how.
Now that you've taken our tour of 9 useful R data viz packages, you probably want to learn about some useless but fun R packages. Check out Ista Zahn's short list here, and enjoy watching what the cow says, or having R tell your fortune.