Skip to content

Instantly share code, notes, and snippets.

@otfrom
Created November 22, 2022 11:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save otfrom/e5fd83a749d4852fc0119b96fddefc69 to your computer and use it in GitHub Desktop.
Save otfrom/e5fd83a749d4852fc0119b96fddefc69 to your computer and use it in GitHub Desktop.
Converting some datasets (badly) into a sankey chart using plotly and clerk
(let [links (tc/dataset
[{:source 0 :target 2 :value 8}
{:source 1 :target 3 :value 4}
{:source 0 :target 4 :value 2}
{:source 2 :target 5 :value 8}
{:source 3 :target 5 :value 4}
{:source 3 :target 5 :value 2}])
nodes (tc/dataset {:label ["red" "orange" "yellow" "green" "blue" "violet"]
:color ["red" "orange" "yellow" "green" "blue" "violet"]})]
(clerk/plotly
{:clerk/width :full}
{:data [{:type "sankey"
:orientation "h"
:valueformat ".0f"
:node {:pad 15
:thickness 30
:line {:color "black" :width 0.5}
:label (into [] (nodes :label))
:color (into [] (nodes :color))}
:link {:source (into [] (links :source))
:target (into [] (links :target))
:value (into [] (links :value))}}]
:layout {:title "Basic Sankey"
:width 1024
:height 1024
:font {:size 10}}
:config {:displayModeBar false
:displayLogo false}}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment