Skip to content

Commit 696cedf

Browse files
committed
triple-view plot working
1 parent 5e44d21 commit 696cedf

1 file changed

Lines changed: 45 additions & 28 deletions

File tree

src/data_visualization/violin2.clj

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -303,46 +303,63 @@
303303

304304
;;; well that doesn't work
305305

306+
307+
308+
306309
^:kind/vega-lite
307-
{:data
308-
{:url
309-
"https://raw.githubusercontent.com/ttimbers/palmerpenguins/refs/heads/file-variants/inst/extdata/penguins.tsv",
310-
:format {:type "tsv"}},
311-
:config {:facet {:spacing 0}, :view {}},
310+
{:data {:values (tc/rows penguin-data :as-maps)}
311+
:config {:facet {:spacing 0}
312+
:view {}}
312313
:facet
313-
{:row {:field "species island", :type :nominal, :header {:labelAngle 0, :labelAlign "left"}}},
314+
{:row {:field "species island"
315+
:type :nominal
316+
:header {:labelAngle 0 :labelAlign "left"}}}
314317
:spec
315-
{ :height 50,
318+
{:height 50
316319
:width 800
317-
:resolve {:scale {:y "independent"}},
320+
:resolve {:scale {:y "independent"}}
318321
:layer
319-
[{:mark {:type "point", :tooltip {:content :data}},
320-
:transform [{:calculate "random()", :as "jitter"}],
322+
[
323+
;; Violins
324+
{:mark {:type :area :orient :vertical}
325+
:transform [{:density "body_mass_g"
326+
:groupby ["species island"]
327+
:bandwidth 80
328+
:extent [2200 6800]}]
321329
:encoding
322-
{:x {:field "body_mass_g", :type :quantitative, :scale {:zero false}},
330+
{:color {:field "species island" :type :nominal :legend false}
331+
:x {:field "value" :type :quantitative :title "body_mass_g"}
332+
:y {:field "density" :type :quantitative :stack :center :axis false}
333+
:opacity {:value 0.7}
334+
}
335+
}
323336

324-
:y {:field "jitter", :type :quantitative, :axis false},
325-
:color {:field "species island", :type :nominal, :legend false}},
337+
;; Points
338+
{:mark {:type "point" :tooltip {:content :data}}
339+
:transform [{:calculate "random()" :as "jitter"}]
340+
:encoding
341+
{:x {:field "body_mass_g" :type :quantitative :scale {:zero false}}
342+
:y {:field "jitter" :type :quantitative :axis false}
343+
}
326344
}
345+
346+
;; Box
327347
{:mark
328-
{:type :boxplot,
329-
:tooltip {:content :data},
330-
:extent :min-max,
331-
:box {:strokeWidth 1.5, :stroke "gray"}},
332-
:transform [{:calculate "random()", :as "jitter"}],
348+
{:type :boxplot
349+
:tooltip {:content :data}
350+
:extent :min-max
351+
:box {:strokeWidth 1.5 :stroke "gray"}}
352+
:transform [{:calculate "random()" :as "jitter"}]
333353
:encoding
334-
{:x {:field "body_mass_g", :type :quantitative, :scale {:zero false}},
354+
{:x {:field "body_mass_g"
355+
:type :quantitative
356+
:scale {:zero false}}
357+
:fill {:value "none"}
358+
:stroke {:value "black"}
359+
}
335360

336-
:color {:field "species island", :type :nominal, :legend false}},
337361
}
338-
{:mark {:type :area, :orient :vertical},
339-
:transform [{:density "body_mass_g" :groupby ["species island"]}],
340-
:encoding
341-
{:color {:field "species island", :type :nominal, :legend false},
342-
:x {:field "value", :type :quantitative, :title "body_mass_g", #_ :scale #_ {:zero false}},
343-
:y {:field "density", :type :quantitative, :stack :center, :axis false},
344-
},
345-
}],
362+
]
346363
}}
347364

348365

0 commit comments

Comments
 (0)