Make ggplot graphics2 interactive with ggiraph

October 10, 2016
By

(This article was first published on Revolutions, and kindly contributed to R-bloggers)

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 on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Sponsors

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)