What this article covers

A typical flyover workflow has the following steps:

  1. Combine different data sets into a single table.
  2. Apply a plotting function to the columns of the table.
  3. Build a display to navigate the plots.

This vignette will introduce step 3: how flyover makes use of the trelliscopejs package to turn your tibble of plots into visual wonders.

This vignette assumes you have a single data set composed of data from different groups for comparison. We will show how to use that data to build a trelliscope display for the purpose of scanning distributional differences between those groups.

Data for this example

The data used in this example is the same as in the previous article (“Creating plots”).

str(my_data)
## tibble [200 × 10] (S3: tbl_df/tbl/data.frame)
##  $ source: chr [1:200] "old" "old" "old" "old" ...
##  $ norm  : num [1:200] 1.586 1.709 0.891 0.547 1.606 ...
##  $ exp   : num [1:200] 0.1772 0.0858 0.3273 0.5311 2.5615 ...
##  $ chisq : num [1:200] 4.53 6.54 4.92 3.55 2.71 ...
##  $ lnorm : num [1:200] 1.024 0.619 1.016 4.919 1.054 ...
##  $ gamma : num [1:200] 0.866 0.89 0.549 1.02 0.948 ...
##  $ alpha : chr [1:200] "c" "b" "a" "d" ...
##  $ hilo  : chr [1:200] "high" "low" "low" "low" ...
##  $ tf    : logi [1:200] TRUE FALSE TRUE TRUE FALSE TRUE ...
##  $ fruit : chr [1:200] "pear" "pear" "apple" "pear" ...

Building and using displays

To build a display, we choose a plotting function and create plotting data as seen in the previous article. Then we pass this data to build_display, give the display a name, and specify a directory for the display output (this is where plots and trelliscope app files live).

The following code would render a display in an R Mardown document (see the tips below for rendering displays). Notice that the display is interactive, allowing you to page through multiple plots, change the grid size, add and remove cognostic (metadata) labels, filter plots by cognostics, and sort them on the same features. Sorting and filtering the plots is a powerful way to cut out noise and focus on the plots where the most important changes are taking place. For example, if you were interested in the variables demonstrating the greatest variation in central tendency, you migth sort by pct_change_median descending. (See ?build_display for how to set the default sorting cognostic.)

my_hist <- build_plots(my_data, flyover_histogram, group_var = "source")
build_display(my_hist,
              display_name = "histogram",
              output_dir   = "display-histogram")

Different views on your data

This package makes it easy to break down data sets in different ways and compare distributions. For example, if we decide we are interested in numeric distributions across different kinds of fruit, we could change the plotting function and the grouping variable:

my_binline <- build_plots(my_data, flyover_binline_ridges, group_var = "fruit")
build_display(my_binline,
              display_name = "binline-ridges",
              output_dir   = "display-binline-fruit")

Tips for rendering displays

There are three common ways you can render a display:

  1. build the display from an R script and point a browser at the output directory (e.g. if you are serving files from localhost);
  2. embed the display in an iframe, pointing src to the display output;
  3. render the display from an R Mardown, ensuring that the build_display call is the last line of a code chunk and the output directory is a relative file path.

Finally, you can change the way your display initializes. Advanced trelliscopejs controls can be passed via .... See documentation here.

Using a pipe

Notice that these functions – indeed, all the functions in this package – are data-first, meaning they are pipe-friendly. Thus you could in theory write a pipeline like this:

old %>%
  enlist_data(new, names = c("old data", "new data")) %>%
  stack_data() %>%
  build_plots(flyover_histogram) %>%
  build_display("histograms", "display-histograms")