Skip to content

Commit e8bcb5e

Browse files
committed
tableplot param flow
1 parent f9f9509 commit e8bcb5e

File tree

1 file changed

+27
-23
lines changed

1 file changed

+27
-23
lines changed

src/data_visualization/tableplot_parameter_flow.clj

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@
2929
;;
3030
;; This tutorial is a brief intro to this feature.
3131

32+
;; ::: {.callout-tip collapse="true"}
3233
;; ### Background: The Layered Grammar of Graphics
3334
;;
34-
;; 💡 *(can skip on first read)*
35-
;;
3635
;; Tableplot is inspired by the [**layered grammar of graphics**](https://vita.had.co.nz/papers/layered-grammar.html),
3736
;; a framework for understanding and building statistical visualizations. Originally developed by
3837
;; Leland Wilkinson and later refined by Hadley Wickham in ggplot2, the grammar views plots as
@@ -59,7 +58,9 @@
5958
;; - [Demystifying stat_ layers in ggplot2](https://yjunechoe.github.io/posts/2020-09-26-demystifying-stat-layers-ggplot2/) - June Choe's exploration of how the grammar elegantly handles data transformations, with special focus on making the internals observable and extensible
6059
;; - [Analyzing Data with Clojure (Kevin Lynagh, 2012)](https://www.youtube.com/watch?v=xyGggdg31mc) - An early Clojure attempt to handle the challenge of building a grammar of graphics
6160

62-
;; ## The Challenge: Customizing Grid Colors
61+
;; :::
62+
63+
;; ## A toy challenge: Customizing Grid Colors
6364
;;
6465
;; Let's start with a basic dataset and plot.
6566

@@ -69,8 +70,6 @@
6970
(tc/dataset {:x [1 2 3 4 5]
7071
:y [2 4 3 5 7]}))
7172

72-
sample-data
73-
7473
;; In this tutorial, we'll use Tableplot's [Plotly.js](https://plotly.com/javascript/) API,
7574
;; which generates interactive Plotly.js visualizations. Tableplot also supports other backends
7675
;; like Vega-Lite and an experimental transpilation API.
@@ -83,18 +82,8 @@ sample-data
8382
(plotly/layer-point {:=mark-size 20})
8483
plotly/layer-line)
8584

86-
;; ### Goal
87-
88-
;; Assume that we now wish to colour the grid lines: vertical by green,
89-
;; horizontal by red. After all, what would be a
90-
;; better way to teach Tufte's [data-ink ratio](https://infovis-wiki.net/wiki/Data-Ink_Ratio) principle than doing exactly
91-
;; what it asks us to avoid, by adding some chartjunk?
92-
93-
;; Here are a few ways we can do it.
94-
85+
;; ::: {.callout-tip collapse="true"}
9586
;; ### A brief look inside
96-
;;
97-
;; 💡 *(can skip on first read)*
9887

9988
;; By default, when used in [Kindly](https://scicloj.github.io/kindly-noted/)-compatible
10089
;; tools like [Clay](https://scicloj.github.io/clay/) and in Clojure Civitas posts,
@@ -136,6 +125,17 @@ sample-data
136125
plotly/plot
137126
kind/pprint)
138127

128+
;; :::
129+
130+
;; ### Goal
131+
132+
;; Assume that we now wish to colour the grid lines: vertical by green,
133+
;; horizontal by red. After all, what would be a
134+
;; better way to teach Tufte's [data-ink ratio](https://infovis-wiki.net/wiki/Data-Ink_Ratio) principle than doing exactly
135+
;; what it asks us to avoid, by adding some chartjunk?
136+
137+
;; Here are a few ways we can do it.
138+
139139
;; ## Using the relevant substitution keys
140140

141141
;; Sometimes, what we need can be precisely specified in Tableplot.
@@ -154,9 +154,8 @@ sample-data
154154
(plotly/layer-point {:=mark-size 20})
155155
plotly/layer-line)
156156

157+
;; ::: {.callout-tip collapse="true"}
157158
;; ### A brief look inside
158-
;;
159-
;; 💡 *(can skip on first read)*
160159

161160
;; Let us see what actually has changed in the
162161
;; resulting specification:
@@ -169,6 +168,8 @@ sample-data
169168
plotly/plot
170169
kind/pprint)
171170

171+
;; :::
172+
172173
;; ## Overriding a broader-scope key
173174

174175
;; Sometimes, you will not find exactly what you need in Tableplot's
@@ -198,13 +199,12 @@ sample-data
198199
;; Notice that a few other details of the aesthetics have changed,
199200
;; like the plot's background color.
200201

201-
;; That is what happens when we override the whole `:layout`.
202+
;; That is what happens when we override the whole `:=layout`.
202203
;; It is a powerful option, that you may or may not like, depending on
203204
;; your use case.
204205

206+
;; ::: {.callout-tip collapse="true"}
205207
;; ### A brief look inside
206-
;;
207-
;; 💡 *(can skip on first read)*
208208

209209
;; Let us see what happens:
210210

@@ -225,6 +225,8 @@ sample-data
225225
;; in our previous example, we actually went through affecting the
226226
;; broad-scope key, `:=layout`.
227227

228+
;; :::
229+
228230
;; ## Direct Manipulation After `plotly/plot`
229231

230232
;; Sometimes, you wish to work with Plotly.js high-level notions,
@@ -236,6 +238,7 @@ sample-data
236238
;; [It's just data](https://www.youtube.com/watch?v=jlPaby7suOc&t=1000s).
237239

238240
;; We do not need to use Tableplot's API for everything.
241+
;;
239242
;; After we call `plotly/plot`, we can process the actual Plotly.js
240243
;; specification, as data.
241244

@@ -246,9 +249,8 @@ sample-data
246249
(assoc-in [:layout :xaxis :gridcolor] "green")
247250
(assoc-in [:layout :yaxis :gridcolor] "red"))
248251

252+
;; ::: {.callout-tip collapse="true"}
249253
;; ### A brief look inside
250-
;;
251-
;; 💡 *(can skip on first read)*
252254

253255
;; You already know what to expect here:
254256

@@ -260,6 +262,8 @@ sample-data
260262
(assoc-in [:layout :yaxis :gridcolor] "red")
261263
kind/pprint)
262264

265+
;; :::
266+
263267
;; ## Summary
264268
;;
265269
;; Tableplot's parameter substitution system gives you three levels of control:

0 commit comments

Comments
 (0)