Get startedGet started for free

Faceting with TrelliscopeJS

1. Faceting with TrelliscopeJS

In the previous chapter, we finished with an example where we were considering applying the same visualization to many subsets of the data to inspect whether the observed taxi cash tipping phenomenon was consistent across all taxi routes.

2. Faceting with TrelliscopeJS

The result would essentially be a massive faceted display with thousands of panels. Creating and viewing such a display sounds daunting and impossible, but this kind of scalable detailed visualization is easily achievable with an exciting new package, TrelliscopeJS. TrelliscopeJS is a powerful tool to have in your toolbox when visualizing large or even moderate size datasets. The remainder of this course will introduce and cover different ways to use this approach.

3. The Gapminder data

In this chapter, we will use the Gapminder dataset we briefly visited in chapter 1 to illustrate what TrelliscopeJS is and how it works.

4. Life expectancy over time per country

The gapminder dataset contains a yearly measure of life expectancy for each country. Suppose we wish to gain insights into the trajectory of life expectancy over time for each country. We can try to look at this with a line plot grouped by country. There are too many countries to look at on the same plot. To reduce overplotting, this is a good candidate for faceting.

5. Faceting on continent

Let's try get more clarity by faceting on continent. We make the same plot as before, but add a faceting directive and also vary color by continent to provide additional visual differentiation. This plot is helpful in uncovering some new insights, such as the variability of the trajectories within and between continents. We can also see some of the individual trajectories more clearly. However, it appears that some trajectories are not strictly increasing, and we'd like to get even more clarity. Let's try faceting on country.

6. Faceting on country

Here we look at life expectancy vs. time faceting on country and continent. Although it is redundant to use continent as a faceting variable, we include it so that we can see which continent the country belongs to in the labeling. Viewing the resulting plot in a standard size viewport, the labels get in the way! There are 142 countries, too many to look at at once. Even with a small dataset, we have a problem with too many facets. This is where TrelliscopeJS can help.

7. Faceting with TrelliscopeJS

With TrelliscopeJS, ggplot2 faceting is as easy as swapping out facet_wrap with facet_trelliscope. This will provide you with an interactive faceted display that shows a grid of plots with the ability to page through the plots if there are too many to fit on one page. The facet_trelliscope() function has a few arguments in common with facet_wrap(), namely nrow and ncol which specify the layout of the grid. Additional basic parameters that you can provide are a name and description as well as a location where to store the output on your computer.

8. Let's practice!

Let's give TrelliscopeJS a try. In the following exercises, you will use a very small subset of the gapminder data. This is to ensure that execution time is fast as you iterate on getting the correct result. The resulting displays will not be very meaningful due to the small subset of the data being used, but each code exercise will be followed by an exploration exercise that uses the full dataset.