block by timelyportfolio c73fe44ffff242f80210d5b8841ab9e2

trelliscope and sparkline example

Full Screen

Thanks so much to Ryan Hafen for his R and JS work on trelliscopejs.

I did not have enough time to figure out how to save the trelliscopejs widget as html, so I took the easy route with an animated GIF. Here is the code to reproduce this simple example.

Code

library(trelliscopejs)
library(dplyr)
library(tidyr)
library(sparkline)

mpg %>%
  group_by(manufacturer, class) %>%
  summarise(
    mean_city_mpg = cog(mean(cty), desc = "Mean city mpg"),
    mean_hwy_mpg = cog(mean(hwy), desc = "Mean highway mpg"),
    panel = panel(
      sparkline(
        unname(c(
          mean(.$cty),
          mean(cty),
          rev(quantile(.$cty,probs=c(1/3,2/3,1)))
        )),
        type="bullet",
        chartRangeMin=0,
        chartRangeMax=max(.$cty)
      )
    )
  ) %>%
  trelliscope(name = "city_vs_highway_mpg", nrow = 4, ncol = 8)

index.html

<!DOCTYPE html>
<head>
  <meta charset="utf-8">
  <style>
    body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
  </style>
</head>

<body>
  <h1>Animated GIF of trelliscopejs and sparkline</h1>
  <img alt="animated screenshot of trelliscope and sparkline" src="//imgur.com/download/I0xOptL" width=960></img>
</body>