1. Additional TrelliscopeJS features
A major goal of TrelliscopeJS is to provide many potentially useful behaviors with little effort or configuration. As an example, you have seen already the "cognostics" that are automatically computed based on the data passed in to the plot.
In this lesson, I will show you how you can easily add interactivity inside your ggplot2 panels, compute cognostics automatically based on the context of what is being plotted, and set axis limit ranges with a few simple commands.
2. ggplot panel interactivity using Plotly
In addition to the interactivity TrelliscopeJS provides for exploring across panels, an easy way to add some interactivity within panels is to use the as_plotly argument to facet_trelliscope(). This uses the plotly R package to transform your ggplot2 panels into interactive plotly graphics.
3. ggplot panel interactivity using Plotly
Now with hardly any effort we have features like tooltips and zooming for free.
The as_plotly functionality may not always be compatible with the type of plot you are making, but this is generally a good option for adding quick interactivity within panels. In the next chapter, you will learn about how you can use plotting systems outside of ggplot2 to create TrelliscopeJS displays.
4. Context-based automatic cognostics
TrelliscopeJS has capability to calculate cognostics automatically based on the context of a ggplot2 plot, giving you additional potentially useful metrics to explore the panels. The specified layers of your ggplot2 specification are analyzed to determine the appropriate cognostics to calculate.
To enable this feature, you simply need to add auto_cog equals TRUE to your call to facet_trelliscope(). You can learn more about the different types of auto cognostics by looking at the help entry for autocog in the autocogs package.
5. Context-based automatic cognostics
Here we see new scatterplot cognostics such as _scagnostic_monotonic, which is a squared measure of the Pearson's correlation coefficient, to see which panels have the most or least linear correlation.
6. Axis limits
A very important aspect of multipanel display is axis limits. The way the axis limits for each panel are computed greatly impacts the visual comparisons that can be made across panels.
TrelliscopeJS provides built-in support for control of axis limits through the scales argument, which is similar to the argument in ggplot2's facet_wrap(). We'll cover the three options "same", "sliced", and "free".
7. scales = "same"
In all examples that you have seen so far, the axis limits have been the same across all panels, which is the default behavior. This is useful for making "apples to apples" scale comparisons across the panels.
8. scales = "sliced"
When scales are "sliced", each panel's axis limits span the same range, but the starting point can shift based on the data in the panel.
For example, here we see the same three countries as before, with each panel's y-axis spanning about 30 years life expectancy, but we can more easily compare the progression of each over time. In the previous example with "same" axes, we could see how Iceland has a higher overall mean life expectancy, but in this example with "sliced" axes, we can see more clearly that Cambodia has had a greater increase in life expectancy.
Sliced axes can be useful when visualizing data for which the values across panels span a very large range to the point that "same" axes do not allow for a more concentrated view of variability within panels.
Note that "sliced" axes are currently not available in ggplot2, only in TrelliscopeJS.
9. scales = "free"
A third option is "free" axes, in which case each panel's limits are based on the bounds of its data. It can be useful to use free axes as a first pass when panels have large outliers that cause the other axis approaches to fail.
10. Let's practice!
Let's try out some of these options.