<p>In response to a user’s request and after a short conversation with Carson Sievert (creator / maintainer of the <a href="https://github.com/ropensci/plotly">plotly</a> R package), I recently made a small tweak to <a href="https://hafen.github.io/trelliscopejs/">TrelliscopeJS</a> to make it very easy to create Trelliscope displays with interactive Plotly panels. A simple example is shown in this post.</p>
<p>If you missed <a href="http://ryanhafen.com/blog/trelliscopejs">earlier</a> <a href="http://ryanhafen.com/blog/insta-trelliscopejs">posts</a> on <a href="https://hafen.github.io/trelliscopejs">TrelliscopeJS</a>, 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 <a href="https://github.com/ropensci/plotly">plotly</a> package is an htmlwidget, it plugs in very easily.</p>
<p>To run this example, you’ll need the following packages installed. Note that you reinstall TrelliscopeJS to get the updated functionality.</p>
<pre><code>devtools::install_github(&quot;hafen/trelliscopejs&quot;)
install.packages(c(&quot;gapminder&quot;, &quot;plotly&quot;, &quot;ggplot2&quot;))

library(trelliscopejs)
library(ggplot2)
library(plotly)
library(gapminder)
</code></pre>
<p>There is a new parameter in <code>facet_trelliscope()</code>, <code>as_plotly</code>, that if set to <code>TRUE</code> will simply convert each ggplot2 panel to an interactive Plotly plot.</p>
<pre><code>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)
</code></pre>
<p>Pretty simple. The output will look like this:</p>
<div>
<div></div>
</div>
<p>If this display doesn’t appear correctly for you (because of blog aggregators, etc.), you can follow <a href="http://hafen.github.io/trelliscopejs-demo/gapminder_plotly/">this link</a> 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.</p>
<p>Note that the code above is identical to what you would write with ggplot2 except that you simply swap <code>facet_wrap()</code> for <code>facet_trelliscope()</code> and add a few extra parameters to the facet command to specify the initial layout of the display.</p>
<p>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 <code>trelliscope()</code> interface. You can see an example of this idea using <a href="http://hafen.github.io/rbokeh/">rbokeh</a> in <a href="http://ryanhafen.com/blog/trelliscopejs">my first blog post on TrelliscopeJS</a>.</p>