Andrea Amantini / May 10 2019
Remix of Clojure by Nextjournal

Clojure Oz Enviroment

{:deps
 {org.clojure/clojure {:mvn/version "1.10.0"}
  metasoarous/oz {:mvn/version "1.5.6"}}}
deps.edn
Extensible Data Notation

You can add dependencies by modifying the deps.edn above (requires a runtime restart)...

(require '[oz.core :as oz])

Let's define a small helper function to use oz to plot to an iframe.

(defn oz-plot [data]
  {:nextjournal/viewer "iframe" :nextjournal.viewer/value (oz/html data)})
user/oz-plot

Now let's create some play 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)))}))
user/play-data
(def line-plot
  {:data {:values (play-data "monkey" "slipper" "broom")}
   :encoding {:x     {:field "time"}
              :y     {:field "quantity"}
              :color {:field "item" :type "nominal"}}
   :mark "line"})
(oz-plot line-plot)
(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-plot stacked-bar)