Oz
Data visualizations in Clojure and ClojureScript using Vega and Vega-lite
Install / Use
/learn @metasoarous/OzREADME
Great and powerful scientific documents & data visualizations
<br/>Please use 1.6.0-alpha36 for the most recent stable version of Oz.
For the latest notebook and async data & document processing capabilities, please try out the 2.0.0-alpha5, but note that it may have some bugs still.
Overview
Oz is a data visualization and scientific document processing library for Clojure built around Vega-Lite & Vega.
Vega-Lite & Vega are declarative grammars for describing interactive data visualizations.
Of note, they are based on the Grammar of Graphics, which served as the guiding light for the popular R ggplot2 viz library.
With Vega & Vega-Lite, we define visualizations by declaratively specifying how attributes of our data map to aesthetic properties of a visualization.
Vega-Lite in particular focuses on maximal productivity and leverage for day to day usage (and is the place to start), while Vega (to which Vega-Lite compiles) is ideal for more nuanced control.
About oz specifically...
Oz itself provides:
view!: Clojure REPL API for for pushing Vega-Lite & Vega (+ hiccup) data to a browser window over a websocketvega,vega-lite: Reagent component API for dynamic client side ClojureScript appspublish!: create a GitHub gist with Vega-Lite & Vega (+ hiccup), and print a link to visualize it with either the IDL's live vega editor or the ozviz.ioload: load markdown, hiccup or Vega/Vega-Lite files (+ combinations) from disk as EDN or JSONexport!: write out self-contained html files with live/interactive visualizations embeddedoz.notebook.<kernel>: embed Vega-Lite & Vega data (+ hiccup) in Jupyter notebooks via the Clojupyter & IClojure kernelslive-reload!: live clj code reloading (à la Figwheel), tuned for data-science hackery (only reruns from first changed form, for a pleasant, performant live-coding experience)live-view!: similar Figwheel-inspiredlive-view!function for watching andview!ing.md,.ednand.jsonfiles with Vega-Lite & Vega (+ (or markdown hiccup))build!: generate a static website from directories of markdown, hiccup &/or interactive Vega-Lite & Vega visualizations, while being able to see changes live (as withlive-view!)
Learning Vega, Vega-Lite & Oz
To take full advantage of the data visualization capabilities of Oz, it pays to understanding the core Vega & Vega-Lite. If you're new to the scene, it's worth taking a few minutes to orient yourself with this mindblowing talk/demo from the creators at the Interactive Data Lab (IDL) at University of Washington.
Watched the IDL talk and hungry for more content? Here's another which focuses on the philosophical ideas behind Vega & Vega-Lite, how they relate to Clojure, and how you can use the tools from Clojure using Oz.
This Readme is the canonical entry point for learning about Oz. You may also want to check out the cljdoc page (if you're not there already) for API & other docs, and look at the examples directory of this project (references occassionally below).
Ecosystem
Some other things in the Vega/Vega-Lite ecosystem you may want to look at for getting started or learning more
- Vega Editor - Wonderful editing tool (as mentioned above) for editing and sharing Vega/Vega-Lite data visualizations.
- Ozviz - Sister project to Oz: A Vega Editor like tool for sharing (and soon editing) hiccup with embedded Vega/Vega-Lite visualizations, as used with the
view!function. - Voyager - Also from the IDL, Voyager is a wonderful Tableau like (drag and drop) tool for exploring data and constructing exportable Vega/Vega-Lite visualizations.
- Vega Examples & Vega-Lite Examples - A robust showcase of visualizations from which to draw inspiration and code.
- Vega home - More great stuff from the IDL folks.
REPL Usage
If you clone this repository and open up the dev/user.clj file, you can follow along by executing the
commented out code block at the end of the file.
Assuming you're starting from scratch, first add oz to your leiningen project dependencies
Next, require oz and start the plot server as follows:
(require '[oz.core :as oz])
(oz/start-server!)
This will fire up a browser window with a websocket connection for funneling view data back and forth. If you forget to call this function, it will be called for you when you create your first plot, but be aware that it will delay the first display, and it's possible you'll have to resend the plot on a slower computer.
Next we'll define a function for generating some dummy data
(defn play-data [& names]
(for [n names
i (range 20)]
{:time i :item n :quantity (+ (Math/pow (* i (count n)) 0.8) (rand-int (count n)))}))
oz/view!
The main function for displaying vega or vega-lite is oz/view!.
For example, a simple line plot:
(def line-plot
{:data {:values (play-data "monkey" "slipper" "broom")}
:encoding {:x {:field "time" :type "quantitative"}
:y {:field "quantity" :type "quantitative"}
:color {:field "item" :type "nominal"}}
:mark "line"})
;; Render the plot
(oz/view! line-plot)
Should render something like:

Another example:
(def stacked-bar
{:data {:values (play-data "munchkin" "witch" "dog" "lion" "tiger" "bear")}
:mark "bar"
:encoding {:x {:field "time"
:type "ordinal"}
:y {:aggregate "sum"
:field "quantity"
:type "quantitative"}
:color {:field "item"
:type "nominal"}}})
(oz/view! stacked-bar)
This should render something like:

vega support
For vega instead of vega-lite, you can also specify :mode :vega to oz/view!:
;; load some example vega (this may only work from within a checkout of oz; haven't checked)
(require '[cheshire.core :as json])
(def contour-plot (oz/load "examples/contour-lines.vega.json"))
(oz/view! contour-plot :mode :vega)
This should render like:

Hiccup
We can also embed Vega-Lite & Vega visualizations within hiccup documents:
(def viz
[:div
[:h1 "Look ye and behold"]
[:p "A couple of small charts"]
[:div {:style {:display "flex" :flex-direction "row"}}
[:vega-lite line-plot]
[:vega-lite stacked-bar]]
[:p "A wider, more expansive chart"]
[:vega contour-plot]
[:h2 "If ever, oh ever a viz there was, the vizard of oz is one because, because, because..."]
[:p "Because of the wonderful things it does"]])
(oz/view! viz)
Note that the Vega-Lite & Vega specs are described in the output vega as using the :vega and :vega-lite keys.
You should now see something like this:

Note that vega/vega-lite already have very powerful and impressive plot concatenation features which allow for coupling of interactivity between plots in a viz. However, combing things through hiccup like this is nice for expedience, gives one the ability to combine such visualizations in the context of HTML documents.
Also note that while not illustrated above, you can specify multiple maps in these vectors, and they will be merged into one.
So for example, you can do [:vega-lite stacked-bar {:width 100}] to override the width.
As client side reagent components
If you like, you may also use the Reagent components found at oz.core to render vega and/or vega-lite you construct client side.
[:div
[oz.core/vega { ... }]
[oz.core/vega-lite { ... }]]
At present, these components do not take a second argument. The merging of spec maps described above applies prior to application of this reagent component.
Eventually we'll be adding options for hooking into the signal dataflow graphs within these visualizations so that interactions in a Vega/Vega-Lite visualization can be used to inform other Reagent components in your app.
Please note that when using oz.core client side, the :data entry in your vega spec map should not be nil (for example you're loading data into a reagent atom which has not been populated yet). Instead prefer an empty sequence () to avoid hard to diagnose errors in the browser.
Loading specs
Oz now features a load function which accepts the following formats:
edn,json,yaml: directly parse into hiccup &/or Vega/Vega-Lite representationsmd: loads a markdown file, with a notation for specifying Vega/Vega-Lite in code blocks tagged with thevega,vega-liteorozclass
As example of the markdown syntax:
# An example markdown file
```edn vega-l
Related Skills
node-connect
339.1kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
83.8kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
339.1kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
83.8kCommit, push, and open a PR


