TrelliscopeJS with Plotly

December 21, 2016
By

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

In response to a user’s request and after a short conversation with Carson Sievert (creator / maintainer of the plotly R package), I recently made a small tweak to TrelliscopeJS to make it very easy to create Trelliscope displays with interactive Plotly panels. A simple example is shown in this post.

If you missed earlier posts on TrelliscopeJS, it is an R package that brings faceted visualizations to life while plugging in to common analytical workflows like ggplot2 or the “tidyverse”, allowing full latitude in what underlying plotting library is used (ggplot2, lattice, htmlwidgets). Since the R plotly package is an htmlwidget, it plugs in very easily.

To run this example, you’ll need the following packages installed. Note that you reinstall TrelliscopeJS to get the updated functionality.

devtools::install_github("hafen/trelliscopejs")
install.packages(c("gapminder", "plotly", "ggplot2"))

library(trelliscopejs)
library(ggplot2)
library(plotly)
library(gapminder)

There is a new parameter in facet_trelliscope(), as_plotly, that if set to TRUE will simply convert each ggplot2 panel to an interactive Plotly plot.

qplot(year, lifeExp, data = gapminder) +
  xlim(1948, 2011) + ylim(10, 95) + theme_bw() +
  facet_trelliscope(~ country + continent,
    nrow = 2, ncol = 6, width = 300, as_plotly = TRUE)

Pretty simple. The output will look like this:

If this display doesn’t appear correctly for you (because of blog aggregators, etc.), you can follow this link to the display in a dedicated window. For better viewing, you can also click the bottom right “fullscreen” button to expand the display to fill the window.

Note that the code above is identical to what you would write with ggplot2 except that you simply swap facet_wrap() for facet_trelliscope() and add a few extra parameters to the facet command to specify the initial layout of the display.

Also note that for even more flexibility you can also create Trelliscope displays with Plotly panels by adding a Plotly object list-column to a data frame and using the trelliscope() interface. You can see an example of this idea using rbokeh in my first blog post on TrelliscopeJS.

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

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)