Skip to content

Commit 83bac8e

Browse files
Merge pull request #101 from ClojureCivitas/macroexpand-civitas
adding macroexpand tableplot for civitas
2 parents 26fcfd4 + 1e1b112 commit 83bac8e

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
^{:clay {:title "Macroexpand 2025 Noj: Civitas Workshop"
2+
:quarto {:author :timothypratley
3+
:description "What is Civitas, why use it, and how to use it."
4+
:type :post
5+
:date "2025-10-17"
6+
:category :clay
7+
:tags [:clay :workflow]}}}
8+
(ns scicloj.tableplot.ideas.macroexpand-workshop-tableplot
9+
(:require [tablecloth.api :as tc]
10+
[scicloj.tableplot.v1.plotly :as tp]))
11+
12+
;; We built this code in the Civitas Workshop,
13+
;; we selected Tableplot as the topic to write about.
14+
15+
16+
;; Everything about Tableplot is inspired by R,
17+
;; there everything is about tables - dataframes.
18+
;; We hope to have our own version of that.
19+
20+
;; It is a limitation at the moment to require a dataset.
21+
22+
(def scatter-ds
23+
(tc/dataset {:x [1 2 3 4 5]
24+
:y [10 20 15 25 18]
25+
:z [1 2 1 2 1]}))
26+
27+
;; Why is the plot not Kindly annotated?
28+
;; Tableplot returns annotated values
29+
30+
(-> scatter-ds
31+
(tp/base {:=title "Sample Scatter Plot"})
32+
(tp/layer-point {:=x :x
33+
:=y :y}))
34+
35+
;; Why is the plot not Kindly annotated?
36+
;; Tableplot returns annotated values
37+
38+
(-> scatter-ds
39+
(tp/base {:=title "Sample Scatter Plot"})
40+
(tp/layer-point {:=x :x
41+
:=y :y})
42+
(meta))
43+
44+
;; The kind is `:kind/fn` which is a transformation.
45+
;; Where is the function?
46+
47+
(-> scatter-ds
48+
(tp/base {:=title "Sample Scatter Plot"})
49+
(tp/layer-point {:=x :x
50+
:=y :y})
51+
(:kindly/f))
52+
53+
;; hidden in the value is the `:kindly/f`.
54+
55+
;; Other types of plots:
56+
57+
;; using layer-bar instead of layer-point
58+
59+
(-> scatter-ds
60+
(tp/base {:=title "Sample Scatter Plot"})
61+
(tp/layer-bar {:=x :x
62+
:=y :y}))
63+
64+
;; We can plot different columns of the dataset
65+
;; as layers.
66+
67+
(-> scatter-ds
68+
(tp/base {:=title "Sample Scatter Plot"})
69+
(tp/layer-line {:=x :x
70+
:=y :z})
71+
(tp/layer-bar {:=x :x
72+
:=y :y}))
73+
74+
;; You don't need a big idea to write a Civitas post,
75+
;; small explorations are welcome.

0 commit comments

Comments
 (0)