Make ggplot graphics2 interactive with ggiraph

[This article was first published on Revolutions, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

R's ggplot2 package is a well-known tool for producing beautiful static data visualizations that you can include in a printed report. But what if you want to include a ggplot2 graphic on a webpage and provide the ability for the user to interact with the data? The ggiraph package by David Gohel  (available for installation via CRAN). WIth ggiraph, you can take an existing ggplot2 bar chart, scatterplot, boxplot, map, or many other types of chart and add one or both of the following iteractions:

  • Display a tooltip of your choice (e.g. data values or labels) when the cursor hovers over sections of the chart
  • Perform an action (a javascript function you provide: jump to another page, for example) when the viewer clicks on an element of the chart

The tweet below (from Duc Quang Nguyen, a data journalist at swissinfo.ch) shows an animation of ggiraph in action: a map of the net migration rate into (green) or out of (brown) regions in Europe.

You can try out other examples of interactive charts in this ggirpah vignette. If you already have chart written in ggplot2, it's easy to make interactive: just replace the existing geom call (e.g. geom_map) with its ggiraph equivalent (geom_map_interactive) , and provide extra arguments with information about the labels and/or javascript actions. For more details on using ggiraph, check out its home on github, linked below.

Github (davidgohel): ggiraph

To leave a comment for the author, please follow the link and comment on their blog: Revolutions.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)