Skip to content

Instantly share code, notes, and snippets.

@ebolyen
Last active April 27, 2022 06:47
Show Gist options
  • Save ebolyen/4a95081fdd0e893b771c604868715588 to your computer and use it in GitHub Desktop.
Save ebolyen/4a95081fdd0e893b771c604868715588 to your computer and use it in GitHub Desktop.
Vega spec from Tue Apr 26 2022
{
"$schema": "https://vega.github.io/schema/vega/v5.json",
"description": "A basic bar chart example, with value labels shown upon mouse hover.",
"width": 400,
"height": 200,
"padding": 5,
"data": [
{
"name": "table",
"values": [
{
"id": "595e93ed.e4b3.42b5.91b1.1ad4f31e7134",
"measure": 7.662921088,
"group": 0,
"subject": "B101"
},
{
"id": "c61b44a5.ae92.4202.9d0c.b4507197e456",
"measure": 8.431734297,
"group": 0,
"subject": "B103"
},
{
"id": "98d36350.175c.439b.a534.27de6e5783ad",
"measure": 8.513263823,
"group": 0,
"subject": "B105"
},
{
"id": "90120dc2.ad2e.4916.a660.633ba4b6a7b8",
"measure": 11.471765618,
"group": 0,
"subject": "B107"
},
{
"id": "fe826a14.1ed8.4d19.b14d.2233b960e1bc",
"measure": 9.914657833,
"group": 0,
"subject": "B109"
},
{
"id": "eb598d02.406f.4ac6.93bd.1d3b8d5682ac",
"measure": 12.625609284,
"group": 0,
"subject": "B111"
},
{
"id": "eda34f8e.ddec.427c.86f1.2a458ef4f7a5",
"measure": 9.453417415,
"group": 0,
"subject": "B113"
},
{
"id": "0a75af43.917b.4ba4.bd50.0607a68a587b",
"measure": 9.646052305,
"group": 0,
"subject": "B115"
},
{
"id": "4a06dba1.77c7.4197.942f.0c8da8b1ab8c",
"measure": 7.778748399,
"group": 0,
"subject": "B117"
},
{
"id": "fa588c8f.129c.4d87.99a5.29048befe11b",
"measure": 12.688779838,
"group": 0,
"subject": "B119"
},
{
"id": "563e291f.d5b9.4d2f.afdf.ef2d7456eb62",
"measure": 11.796326033,
"group": 0,
"subject": "B121"
},
{
"id": "fdd61056.c3a4.4533.bd6f.2f29a4ebf279",
"measure": 7.386190882,
"group": 0,
"subject": "B123"
},
{
"id": "ff88e40f.2c8c.4670.bbdd.ffd35a259b3b",
"measure": 11.197196212,
"group": 0,
"subject": "B127"
},
{
"id": "cfdd76c9.1144.4fb0.87b9.5ea2bda80698",
"measure": 10.187871215,
"group": 0,
"subject": "B131"
},
{
"id": "62b14bee.ba07.4ec5.93bf.c96452f606b5",
"measure": 8.448317067,
"group": 0,
"subject": "B133"
},
{
"id": "c20b61fb.2ca8.426c.b2d0.43b36b7dbe31",
"measure": 11.322819901,
"group": 0,
"subject": "B135"
},
{
"id": "d0296110.6ff1.4959.96d7.74074c23fcdd",
"measure": 7.314753809,
"group": 0,
"subject": "B137"
},
{
"id": "b75f1faa.7d0e.4f5c.bbbb.43c9eee3ca80",
"measure": 8.27086375,
"group": 0,
"subject": "B139"
},
{
"id": "bd64992d.87cc.464f.9e1b.9c0156ed65d8",
"measure": 10.833202094,
"group": 3,
"subject": "B101"
},
{
"id": "59d06f37.995b.40a5.91a8.c825d1a7ca6f",
"measure": 9.8956928,
"group": 3,
"subject": "B103"
},
{
"id": "683047f6.fe17.477f.9950.a6190ca34054",
"measure": 11.869702431,
"group": 3,
"subject": "B105"
},
{
"id": "c1a66804.c565.448a.8371.0c8e386f4969",
"measure": 10.12497616,
"group": 3,
"subject": "B107"
},
{
"id": "98c66ce0.1f4c.422c.86e9.3561ea63b612",
"measure": 9.478838334,
"group": 3,
"subject": "B109"
},
{
"id": "3da00df1.0c79.4428.af4e.b70c506e5613",
"measure": 8.502002897,
"group": 3,
"subject": "B111"
},
{
"id": "c27fbf59.c359.4773.9236.d23daff0faef",
"measure": 9.246871802,
"group": 3,
"subject": "B113"
},
{
"id": "3263647b.bc7d.4256.940c.fcea00129687",
"measure": 12.620007491,
"group": 3,
"subject": "B115"
},
{
"id": "65fcbe4f.1f77.4216.95c1.9991e5f2499a",
"measure": 10.505797973,
"group": 3,
"subject": "B119"
},
{
"id": "5c7870bf.66e4.4024.861e.a586fe550a17",
"measure": 7.830091789,
"group": 3,
"subject": "B121"
},
{
"id": "e48e002a.f4fd.46d4.982e.6fe0854cd48a",
"measure": 6.725748683,
"group": 3,
"subject": "B123"
},
{
"id": "90b5a4f1.85bf.43ba.b100.08c077f4b0cd",
"measure": 11.981833562,
"group": 3,
"subject": "B127"
},
{
"id": "30bb9d5a.9305.4bd8.b193.2b0bff0f3e42",
"measure": 12.436795961,
"group": 3,
"subject": "B131"
},
{
"id": "d43b37cd.6e23.4ccb.8d1a.a05be77c1288",
"measure": 9.592979726,
"group": 3,
"subject": "B133"
},
{
"id": "76295cb2.371f.4a12.824e.7f7209740b44",
"measure": 8.880897012,
"group": 3,
"subject": "B135"
},
{
"id": "18b7bc36.8427.431c.a28c.9a4d0b19f83d",
"measure": 9.092078686,
"group": 3,
"subject": "B137"
},
{
"id": "dc609d92.2073.4db2.aea8.670c816c2fd8",
"measure": 8.522314493,
"group": 3,
"subject": "B139"
},
{
"id": "e7a2370c.f80c.4703.b2ee.10c65967e05f",
"measure": 10.836707037,
"group": 10,
"subject": "B101"
},
{
"id": "8cbe736d.b553.450d.af3c.d5ad08863390",
"measure": 9.172597583,
"group": 10,
"subject": "B103"
},
{
"id": "7e1f1b3f.4575.458c.9f42.287d03499e25",
"measure": 11.606644074,
"group": 10,
"subject": "B105"
},
{
"id": "558a13e5.f4a8.47bc.a63e.47d6dffe528b",
"measure": 10.783456908,
"group": 10,
"subject": "B107"
},
{
"id": "40112074.09e5.42b1.b332.17c9b89686e5",
"measure": 11.481682729,
"group": 10,
"subject": "B109"
},
{
"id": "d256d51b.02ce.450b.8447.f9dc7e949072",
"measure": 17.433704046,
"group": 10,
"subject": "B111"
},
{
"id": "d056b75a.5ff8.4db3.9991.4cc8566d7528",
"measure": 15.262335798,
"group": 10,
"subject": "B113"
},
{
"id": "11d9c298.6eab.4b6b.9665.1dba120f03b2",
"measure": 13.531281489,
"group": 10,
"subject": "B115"
},
{
"id": "4985e68e.e764.43e4.ba6d.c9135cb59802",
"measure": 15.968144505,
"group": 10,
"subject": "B117"
},
{
"id": "d08dfd2b.1f98.47da.b9ee.fc7c8125b3a3",
"measure": 13.610434857,
"group": 10,
"subject": "B119"
},
{
"id": "38cc97e0.b049.40ad.9115.572a0f1fa54b",
"measure": 10.626834586,
"group": 10,
"subject": "B121"
},
{
"id": "bf33f337.90ba.4242.b35f.b1cc0b9a1ead",
"measure": 7.444009936,
"group": 10,
"subject": "B123"
},
{
"id": "709ae56e.5c79.4e56.b054.5bb1522e6a48",
"measure": 9.728676749,
"group": 10,
"subject": "B127"
},
{
"id": "9362298f.4177.4fb2.8a1e.9c4e4d5eb058",
"measure": 12.778745691,
"group": 10,
"subject": "B131"
},
{
"id": "5c70a21a.1611.47be.93bd.1bf502987de1",
"measure": 10.65211873,
"group": 10,
"subject": "B133"
},
{
"id": "7f07b1a5.8b6f.4f33.af95.b41bf6bad858",
"measure": 11.126836757,
"group": 10,
"subject": "B135"
},
{
"id": "58963b05.b9fe.4a36.98e7.f3497c390919",
"measure": 9.027651356,
"group": 10,
"subject": "B137"
},
{
"id": "1709339c.5162.4847.bab8.d492c164537a",
"measure": 9.059711997,
"group": 10,
"subject": "B139"
},
{
"id": "11f3f37a.3698.4031.8183.75f6f2c6c04c",
"measure": 11.687952121,
"group": 18,
"subject": "B101"
},
{
"id": "124dc1db.9029.41c6.afff.b73a692e19b1",
"measure": 10.652627854,
"group": 18,
"subject": "B103"
},
{
"id": "873473f6.eef2.4718.b5f4.e88757055760",
"measure": 10.941844241,
"group": 18,
"subject": "B105"
},
{
"id": "d623471b.5a0c.4291.a780.2ae6532752a9",
"measure": 13.26471277,
"group": 18,
"subject": "B107"
},
{
"id": "ea89c98c.42eb.484a.aed3.33711e20a6fe",
"measure": 11.69071803,
"group": 18,
"subject": "B109"
},
{
"id": "4b7fc783.1008.43aa.9325.896e2e370dee",
"measure": 14.968440776,
"group": 18,
"subject": "B111"
},
{
"id": "66c64e22.7b83.4740.bf41.aa1553f24091",
"measure": 10.49866422,
"group": 18,
"subject": "B113"
},
{
"id": "35a3fb02.a90d.4977.b69e.7fe338ad120d",
"measure": 11.099894914,
"group": 18,
"subject": "B115"
},
{
"id": "097aca46.4d88.4858.9076.a82c0ce1d29b",
"measure": 10.313602107,
"group": 18,
"subject": "B117"
},
{
"id": "86fa2207.97bf.4dda.bfc2.25e1db76807e",
"measure": 11.765702878,
"group": 18,
"subject": "B119"
},
{
"id": "7ee156e0.2353.47bd.b4d0.e6cb56bcd611",
"measure": 13.665533544,
"group": 18,
"subject": "B121"
},
{
"id": "6e911df2.b54d.44a2.8fb8.1b6c1b9c3362",
"measure": 8.598030851,
"group": 18,
"subject": "B123"
},
{
"id": "7bb97977.f259.42e4.96c0.defb321a35f6",
"measure": 11.78182748,
"group": 18,
"subject": "B127"
},
{
"id": "debb2485.5abd.467b.9f85.acba57398d89",
"measure": 12.200703578,
"group": 18,
"subject": "B131"
},
{
"id": "2dfedd8c.5fcf.445f.88b5.9b2ec7e96aec",
"measure": 9.750043462,
"group": 18,
"subject": "B133"
},
{
"id": "e47666f2.3381.46b4.bba1.4245cc970387",
"measure": 10.890809897,
"group": 18,
"subject": "B135"
},
{
"id": "702e5557.ca8d.420d.a802.11257794814d",
"measure": 8.990062701,
"group": 18,
"subject": "B137"
},
{
"id": "9e5630dc.0ab1.4e85.a4e8.24774a6bf46e",
"measure": 14.73197158,
"group": 18,
"subject": "B139"
},
{
"id": "1.ST005",
"measure": 14.952368437,
"group": 100,
"subject": "B101"
},
{
"id": "3.ST005",
"measure": 10.261275033,
"group": 100,
"subject": "B103"
},
{
"id": "5.ST005",
"measure": 12.245579116,
"group": 100,
"subject": "B105"
},
{
"id": "7.ST005",
"measure": 19.963580264,
"group": 100,
"subject": "B107"
},
{
"id": "9.ST005",
"measure": 10.823263552,
"group": 100,
"subject": "B109"
},
{
"id": "11.ST005",
"measure": 12.957318921,
"group": 100,
"subject": "B111"
},
{
"id": "13.ST005",
"measure": 14.46464274,
"group": 100,
"subject": "B113"
},
{
"id": "15.ST005",
"measure": 14.682634367,
"group": 100,
"subject": "B115"
},
{
"id": "19.ST005",
"measure": 15.485695829,
"group": 100,
"subject": "B119"
},
{
"id": "21.ST005",
"measure": 16.049284801,
"group": 100,
"subject": "B121"
},
{
"id": "23.ST005",
"measure": 10.875102638,
"group": 100,
"subject": "B123"
},
{
"id": "27.ST005",
"measure": 8.866448342,
"group": 100,
"subject": "B127"
},
{
"id": "33.ST005",
"measure": 13.570547245,
"group": 100,
"subject": "B133"
},
{
"id": "35.ST005",
"measure": 12.360404461,
"group": 100,
"subject": "B135"
},
{
"id": "37.ST005",
"measure": 11.076843486,
"group": 100,
"subject": "B137"
},
{
"id": "39.ST005",
"measure": 12.988414521,
"group": 100,
"subject": "B139"
}
]
},
{
"name": "jitter_table",
"source": "table",
"transform": [
{"type": "formula", "expr": "sampleUniform()", "as": "jitter"}
]
}
],
"signals": [
{
"name": "width",
"value": 400,
"bind": {"input": "range", "min": 200, "max": 1028}
},
{
"name": "height",
"value": 400,
"bind": {"input": "range", "min": 80, "max": 500}
},
{
"name": "$row_height",
"value": 70,
"bind": {"input": "range", "min": 40, "max": 256}
},
{"name": "$include_zero", "value": true, "bind": {"input": "checkbox"}},
{"name": "$show_rain", "value": true, "bind": {"input": "checkbox"}},
{
"name": "$show_interactions",
"value": true,
"bind": {"input": "checkbox"}
},
{"name": "$show_cloud", "value": true, "bind": {"input": "checkbox"}},
{
"name": "$boxplot_extent",
"value": 0.33,
"bind": {"input": "range", "min": 0, "max": 1}
},
{
"name": "unit",
"value": {},
"on": [
{"events": "mousemove", "update": "isTuple(group()) ? group() : unit"}
]
},
{
"name": "$grid_value",
"on": [
{"events": [{"source": "view", "type": "dblclick"}], "update": "null"},
{
"events": {"signal": "$grid_translate_delta"},
"update": "panLinear($grid_translate_anchor.extent_x, -$grid_translate_delta.x / width)"
},
{
"events": {"signal": "$grid_zoom_delta"},
"update": "zoomLinear(domain(\"measure_scale\"), $grid_zoom_anchor.x, $grid_zoom_delta)"
}
]
},
{
"name": "$grid_translate_anchor",
"value": {},
"on": [
{
"events": [{"source": "view", "type": "mousedown"}],
"update": "{x: x(unit), extent_x: domain(\"measure_scale\")}"
}
]
},
{
"name": "$grid_translate_delta",
"value": {},
"on": [
{
"events": [
{
"source": "window",
"type": "mousemove",
"consume": true,
"between": [
{"source": "view", "type": "mousedown"},
{"source": "window", "type": "mouseup"}
]
}
],
"update": "{x: $grid_translate_anchor.x - x(unit)}"
}
]
},
{
"name": "$grid_zoom_anchor",
"on": [
{
"events": [{"source": "view", "type": "wheel", "consume": true}],
"update": "{x: invert(\"measure_scale\", x(unit))}"
}
]
},
{
"name": "$grid_zoom_delta",
"on": [
{
"events": [{"source": "view", "type": "wheel", "consume": true}],
"force": true,
"update": "pow(1.001, event.deltaY * pow(16, event.deltaMode))"
}
]
}
],
"scales": [
{
"name": "color_scale",
"type": "ordinal",
"domain": {"data": "table", "field": "group", "sort": true},
"range": "category"
},
{
"name": "group_scale",
"type": "band",
"domain": {"data": "table", "field": "group"},
"range": "height",
"padding": 0.1,
"round": true
},
{
"name": "measure_scale",
"domain": {"data": "table", "field": "measure"},
"nice": true,
"range": "width",
"zero": {"signal": "$include_zero"},
"domainRaw": {"signal": "$grid_value"}
},
{
"name": "inner_jitter_scale",
"domain": [0, 1],
"range": [
{
"signal": "scale('inner_boxplot_center_scale', 0) + scale('inner_boxplot_extent_scale', $boxplot_extent)/2 + 7"
},
{"signal": "bandwidth('group_scale') - 7"}
]
},
{
"name": "inner_boxplot_center_scale",
"domain": [0, 1],
"range": [
{
"signal": "$show_cloud == $show_rain ? bandwidth('group_scale')/2 : $show_rain ? scale('inner_boxplot_extent_scale', $boxplot_extent)/2 : bandwidth('group_scale') - scale('inner_boxplot_extent_scale', $boxplot_extent)/2 "
},
0
]
},
{
"name": "inner_boxplot_extent_scale",
"domain": [0, 1],
"range": [
0,
{
"signal": "bandwidth('group_scale') - ($show_rain ? $show_cloud ? 28 : 14 : 0)"
}
]
}
],
"axes": [
{"orient": "bottom", "scale": "measure_scale"},
{"orient": "left", "scale": "group_scale"}
],
"marks": [
{
"type": "group",
"from": {
"facet": {
"name": "subject_table",
"data": "jitter_table",
"groupby": ["subject"]
}
},
"data": [
{
"name": "subject_line_table",
"source": "subject_table",
"transform": [
{"type": "filter", "expr": "$show_rain && $show_interactions"},
{"type": "collect", "sort": {"field": "group"}}
]
}
],
"marks": [
{
"type": "line",
"from": {"data": "subject_line_table"},
"encode": {
"update": {
"x": {"scale": "measure_scale", "field": "measure"},
"y": {
"signal": "scale('group_scale', datum.group) + scale('inner_jitter_scale', datum.jitter)"
},
"stroke": {"value": "lightgrey"},
"strokeOpacity": {"value": 0.5}
}
}
}
]
},
{
"type": "group",
"clip": true,
"from": {
"facet": {
"name": "facet_table",
"groupby": ["group"],
"data": "jitter_table"
}
},
"data": [
{
"name": "facet_kde_table",
"source": "facet_table",
"transform": [
{"type": "filter", "expr": "$show_cloud"},
{"type": "kde", "field": "measure", "groupby": ["group"]}
]
},
{
"name": "facet_rain_table",
"source": "facet_table",
"transform": [{"type": "filter", "expr": "$show_rain"}]
},
{
"name": "facet_boxplot_table",
"source": "facet_table",
"transform": [
{"type": "filter", "expr": "$boxplot_extent > 0"},
{
"type": "aggregate",
"groupby": ["group"],
"ops": ["q1", "q3", "median", "min", "max"],
"fields": ["measure", "measure", "measure", "measure", "measure"]
}
]
},
{
"name": "facet_aesthetic_line_table",
"source": "facet_table",
"transform": [
{"type": "filter", "expr": "$boxplot_extent == 0 && $show_cloud"},
{
"type": "aggregate",
"groupby": ["group"],
"ops": ["min", "max"],
"fields": ["measure", "measure"]
}
]
}
],
"encode": {"update": {"y": {"scale": "group_scale", "field": "group"}}},
"scales": [
{
"name": "inner_kde_scale",
"domain": {"data": "facet_kde_table", "field": "density"},
"range": [{"signal": "scale('inner_boxplot_center_scale', 0)"}, 0]
}
],
"marks": [
{
"type": "area",
"from": {"data": "facet_kde_table"},
"encode": {
"enter": {"fill": {"scale": "color_scale", "field": "group"}},
"update": {
"y": {"scale": "inner_kde_scale", "value": 0},
"y2": {"scale": "inner_kde_scale", "field": "density"},
"x": {"scale": "measure_scale", "field": "value"}
}
}
},
{
"type": "symbol",
"shape": "circle",
"from": {"data": "facet_rain_table"},
"encode": {
"enter": {
"fill": {"scale": "color_scale", "field": "group"},
"opacity": {"value": 0.7}
},
"update": {
"x": {"scale": "measure_scale", "field": "measure"},
"y": {"scale": "inner_jitter_scale", "field": "jitter"}
}
}
},
{
"type": "rule",
"from": {"data": "facet_aesthetic_line_table"},
"encode": {
"enter": {"strokeWidth": {"value": 2}},
"update": {
"x": {"scale": "measure_scale", "field": "min_measure"},
"x2": {"scale": "measure_scale", "field": "max_measure"},
"y": {"scale": "inner_boxplot_center_scale", "value": 0}
}
}
},
{
"type": "group",
"marks": [
{
"type": "rect",
"from": {"data": "facet_boxplot_table"},
"encode": {
"enter": {
"fill": {"scale": "color_scale", "field": "group"},
"strokeWidth": {"value": 2},
"stroke": {"value": "black"},
"cornerRadius": {"value": 2}
},
"update": {
"x": {"scale": "measure_scale", "field": "q1_measure"},
"x2": {"scale": "measure_scale", "field": "q3_measure"},
"yc": {"scale": "inner_boxplot_center_scale", "value": 0},
"height": {
"scale": "inner_boxplot_extent_scale",
"signal": "$boxplot_extent"
}
}
}
},
{
"type": "rule",
"from": {"data": "facet_boxplot_table"},
"encode": {
"enter": {"strokeWidth": {"value": 2}},
"update": {
"x": {"scale": "measure_scale", "field": "min_measure"},
"x2": {"scale": "measure_scale", "field": "q1_measure"},
"y": {"scale": "inner_boxplot_center_scale", "value": 0}
}
}
},
{
"type": "rule",
"from": {"data": "facet_boxplot_table"},
"encode": {
"enter": {"strokeWidth": {"value": 2}},
"update": {
"x": {"scale": "measure_scale", "field": "q3_measure"},
"x2": {"scale": "measure_scale", "field": "max_measure"},
"y": {"scale": "inner_boxplot_center_scale", "value": 0}
}
}
},
{
"type": "rect",
"from": {"data": "facet_boxplot_table"},
"encode": {
"enter": {
"strokeWidth": {"value": 2},
"fill": {"value": "black"}
},
"update": {
"xc": {"scale": "measure_scale", "field": "min_measure"},
"yc": {"scale": "inner_boxplot_center_scale", "value": 0},
"height": {
"scale": "inner_boxplot_extent_scale",
"signal": "$boxplot_extent"
},
"width": {"value": 2}
}
}
},
{
"type": "rect",
"from": {"data": "facet_boxplot_table"},
"encode": {
"enter": {
"strokeWidth": {"value": 2},
"fill": {"value": "black"}
},
"update": {
"xc": {"scale": "measure_scale", "field": "max_measure"},
"yc": {"scale": "inner_boxplot_center_scale", "value": 0},
"height": {
"scale": "inner_boxplot_extent_scale",
"signal": "$boxplot_extent"
},
"width": {"value": 2}
}
}
}
]
}
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment