Tableplot

Easy layered graphics with Hanami & Tablecloth

(-> datasets/economics-long
    (tc/select-rows #(-> % :variable (= "unemploy")))
    (hanami/base {:=x :date
                  :=y :value})
    (hanami/layer-line {:=mark-color "purple"})
    (hanami/update-data tc/random 5)
    (hanami/layer-point {:=mark-color "green"
                         :=mark-size 200}))

See more examples:

1 Preface

Tableplot is a composition of Hanami data visualization templates and Tablecloth datasets.

It adds a simplified set of Hanami templates and defaults alongside those of Hanami, as well as a set of template-processing functions inspired by ggplot2’s layered grammar of graphics.

The current draft was written by Daniel Slutsky, mentored by jsa-aerial (Hanami author) and Kira McLean.

Source: (GitHub repo)

Artifact: (Clojars coordinates)

Status: The API is almost stable and will soon move to beta stage.


An early version of this library was demonstrated in Kira Mclean’s April 2024 talk at London Clojurians:

1.1 Two APIs

Tableplot currently supports two APIs:

  • scicloj.tableplot.v1.hanami generates Vega-Lite plots and parially composes with the classic Hanami templates.

  • scicloj.tableplot.v1.plotly generates the Plotly.js plots.

Each of these APIs builds upon the strengths of its target platform and partially uses its naming and concepts. Thus, the two APIs are not completely compatible. The Plotly-based API is expected to grow a little further in terms of its flexibility and the kinds of idioms it can express.

1.2 Near term plan

  • Stabilize both the Vega-Lite-based API and the Plotly.js-based API as Beta stage.
  • Keep developing main ly the Plotly.js-based API (as it will be more flexible to extend).

1.3 Goals

  • Have a functional grammar for common plotting tasks (but not all tasks).
  • In particular, provide an easy way to work with layers.
  • Be able to pass Tablecloth/tech.ml.dataset datasets directly to the plotting functions.
  • Work out-of-the box in Kindly-supporting tools.
  • By default, infer relevant information from the data (e.g., field types).
  • Catch common errors using the data (e.g., missing fields).
  • Be able to use backend Clojure for relevant statistical tasks (e.g., smoothing by regression, histograms, density estimation).
  • Be able to rely on Vega-Lite/Plotly.js for other some components of the pipeline (e.g., scales and coordinates).
  • Provide simpler Hanami templates, compared to the original ones.
  • Still have the option of using the original Hanami templates.
  • Still be able to use all of Vega-Lite/Plotly.js in its raw format for the highest flexibility.

In the longer term, this project is part of the Scicloj effort to create a grammar-of-graphics visualization library in Clojure.

1.4 Discussion

1.5 Chapters in this book:

source: notebooks/index.clj