Five Interactive R Visualizations With D3, ggplot2, & RStudio

Plotly has a new R API and ggplot2 library for making beautiful graphs. The API lets you produce interactive D3.js graphs with R. This post has five examples. Head to our docs to get a key and you can start making, embedding, and sharing plots. The code below produces our first plot.

Hover to see data, click and drag to zoom, or double-click to autoscale.

 

price vs carat
Key features are: you can share plots with a private or public URL (e.g., https://plot.ly/1143/~RPlotBot/). Interactive graphs can be embedded in knitr docs, dashboards, websites, and Shiny Apps. Updating charts is easy. Users can collaborate from any device or browser in a web app or with Plotly’s APIs for Python and MATLAB.

 

 

Interactive ggplot2 Plotting

Plotly’s ggplot2 converter turns ggplot2 plots into interactive, web-based plots. You can control the tooltip. For example, note the text.

 

 

None, None, None, None, None, Fair, Good, Very Good, Premium, Ideal, Fair, Good, Very Good, Premium, Ideal

 

Plotly is free for online sharing. Licenses are available for on-premise deployments and Plotly Offline. Plotly Offline works inside RStudio:

 

Mix Data Manipulation And Visualization Verbs

Plotly objects are data frames with a class of plotly and an environment that tracks the mapping from data to visual properties.

This allows us to mix data manipulation and visualization verbs in a pure(ly) functional, predictable and pipeable manner. Here, we take advantage of dplyr’s filter() verb to label the highest peak in the time series:

 

Median duration of unemployment (in weeks)

 

3D WebGL

Although data frames can be thought of as the central object in this package, plotly visualizations don’t actually require a data frame. This makes chart types that accept a z argument especially easy to use if you have a numeric matrix:

 

 

Interactive Maps

Plotly also supports interactive maps.

 

2011 US Agriculture Exports by State<br>(Hover for breakdown)

If you have sensitive data, need to collaborate with your team, and need interactive dashboards, contact us about Plotly on-premise. Plotly’s R API was developed by Carson Sievert and Chris Parmer. If you liked what you read, please consider sharing. Find us at feedback@plot.ly and @plotlygraphs.