|
| 1 | +^{:kindly/hide-code true |
| 2 | + :clay {:title "Transforming Datasets to Stack Charts" |
| 3 | + :quarto {:type :post |
| 4 | + :author [:harold] |
| 5 | + :date "2025-06-24" |
| 6 | + :description "A couple of quick ideas about visualizing data, especially with regard to comparison." |
| 7 | + :category :datasets |
| 8 | + :tags [:charts :datasets] |
| 9 | + :keywords [:charts :datasets]}}} |
| 10 | +(ns scicloj.tableplot.ideas.stacking |
| 11 | + (:require [tech.v3.dataset :as ds] |
| 12 | + [scicloj.tableplot.v1.plotly :as plotly])) |
| 13 | + |
| 14 | +;; With observed data, presumably from two runs of some experiment... |
| 15 | + |
| 16 | +(def ds0 |
| 17 | + (ds/->dataset "https://gist.githubusercontent.com/harold/18ba174c6c34e7d1c5d8d0954b48327c/raw" |
| 18 | + {:file-type :csv})) |
| 19 | + |
| 20 | +(def ds1 |
| 21 | + (ds/->dataset "https://gist.githubusercontent.com/harold/008bbcd477bf51b47548d680107a6195/raw" |
| 22 | + {:file-type :csv})) |
| 23 | + |
| 24 | +;; Well, what have we got? |
| 25 | + |
| 26 | +ds0 |
| 27 | + |
| 28 | +;; A few hundred numbers... Hm... |
| 29 | + |
| 30 | +ds1 |
| 31 | + |
| 32 | +;; This neglects the hundreds of thousands of years invested in evolving a visual system... |
| 33 | + |
| 34 | +(-> ds0 |
| 35 | + (plotly/base {:=title "Run 0"}) |
| 36 | + (plotly/layer-point {:=y "y"})) |
| 37 | + |
| 38 | +(-> ds1 |
| 39 | + (plotly/base {:=title "Run 1"}) |
| 40 | + (plotly/layer-point {:=y "y"})) |
| 41 | + |
| 42 | +;; Better; however, our aim is to compare them... Which is higher? |
| 43 | + |
| 44 | +(-> (ds/concat (assoc ds0 :v "Run 0") |
| 45 | + (assoc ds1 :v "Run 1")) |
| 46 | + (plotly/base {:=title "Comparison Between Runs"}) |
| 47 | + (plotly/layer-point {:=y "y" |
| 48 | + :=color :v})) |
| 49 | + |
| 50 | +;; Now it's up to the viewer to decide whether they like higher numbers or not. |
| 51 | + |
| 52 | +;; --- |
| 53 | + |
| 54 | +;; There are a couple of interesting ideas in that last bit of code: |
| 55 | +;; |
| 56 | +;; 1. `assoc` a constant onto a ds creates a constant column |
| 57 | +;; 1. `:=color` takes care of grouping the results and the downstream display |
| 58 | + |
| 59 | +;; Neat. |
0 commit comments