Last active
May 3, 2021 04:18
-
-
Save Misophistful/011842f3b46c046dcd06bd6c3d3d77eb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use 'prc) | |
;;; ----- Bar chart ----- | |
(defn roll-die [num-sides] | |
(inc (rand-int num-sides))) | |
(defn roll-dice [num-sides num-dice] | |
(->> (repeatedly num-dice #(roll-die num-sides)) | |
(reduce +))) | |
(prc/bar-chart "Dice frequencies" | |
(->> (repeatedly 10000 #(roll-dice 6 2)) | |
(frequencies))) | |
;;; ----- Scatter chart ----- | |
(prc/scatter-chart "Dice scatter" | |
{:six (repeatedly 10000 #(roll-dice 6 2)) | |
:ten (repeatedly 10000 #(roll-dice 10 3)) | |
:twenty (repeatedly 10000 #(roll-dice 20 5))}) | |
;;; ----- Graph ------ | |
(def parents->children {["Eddard" "Catelyn"] ["Rob" "Sansa" "Arya" "Bran" "Rickon"] | |
["Eddard" "Wylla"] ["Jon"] | |
["Tywin" "Joanna"] ["Cersei" "Jamie" "Tyrion"]}) | |
(prc/graph "Family Tree" | |
{:nodes (->> parents->children | |
seq | |
flatten | |
distinct) | |
:edges (mapcat #(for [parent (key %) | |
child (val %)] | |
[parent child]) | |
parents->children)} | |
{:nodes {:font {:size 18}} | |
:edges {:arrows {:to {:scaleFactor 0.5} | |
:from {:scaleFactor 0.5}}} | |
:layout {:hierarchical {:enabled true | |
:levelSeparation 150 | |
:direction "UD" | |
:sortMethod "directed"}}}) | |
;;; ----- Timeseries ----- | |
(def row-data (->> (-> (slurp "resources/timeseries.csv") | |
(clojure.string/split #"[,\n]")) | |
(partition 6))) | |
(prc/custom-chart "Timeseries" | |
{:data {:rows row-data | |
:x "Date" | |
:axes {:Volume "y2"}} | |
:axis {:x {:type "timeseries" | |
:tick {:format "%Y-%m-%d"}} | |
:y2 {:show true}}}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment