Skip to content

Instantly share code, notes, and snippets.

@keckelt
Created May 11, 2021 07:59
Show Gist options
  • Save keckelt/64eb3c77b088510f41fd15eddcd85655 to your computer and use it in GitHub Desktop.
Save keckelt/64eb3c77b088510f41fd15eddcd85655 to your computer and use it in GitHub Desktop.
DensityPlot with double click split rulers
{
"$schema": "https://vega.github.io/schema/vega/v5.json",
"autosize": {
"type": "fit-x",
"contains": "padding"
},
"background": "white",
"padding": 5,
"height": 300,
"style": "cell",
"data": [
{
"name": "source_0",
"values": [
{
"tissuename": "TCGA-ZB-A963-01",
"age": 46,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-XM-A8RE-01",
"age": 54,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-XM-A8RF-01",
"age": 84,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-ZB-A96D-01",
"age": 52,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-XU-AAXV-01",
"age": 45,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-ZB-A96P-01",
"age": 73,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-4X-A9FB-01",
"age": 44,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-XM-A8RC-01",
"age": 67,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-4V-A9QQ-01",
"age": 65,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-X7-A8DI-01",
"age": 57,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-ZB-A962-01",
"age": 64,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-XU-A92R-01",
"age": 76,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-X7-A8D8-01",
"age": 53,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-4V-A9QX-01",
"age": 77,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-4V-A9QS-01",
"age": 53,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-3G-AB14-01",
"age": 51,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-X7-A8DD-01",
"age": 54,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-X7-A8DE-01",
"age": 35,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-4V-A9QM-01",
"age": 39,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-ZB-A96Q-01",
"age": 49,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-ZB-A96F-01",
"age": 39,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-4X-A9F9-01",
"age": 57,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-X7-A8DC-01",
"age": 68,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-YT-A95E-01",
"age": 52,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-3G-AB0Q-01",
"age": 66,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-3G-AB0O-01",
"age": 47,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-5K-AAAP-01",
"age": 54,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-5U-AB0F-01",
"age": 58,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-4V-A9QI-01",
"age": 68,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-3T-AA9L-01",
"age": 31,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-X7-A8D6-01",
"age": 48,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-4V-A9QT-01",
"age": 79,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-XM-A8R9-01",
"age": 71,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-3S-AAYX-01",
"age": 55,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-XM-A8RB-01",
"age": 68,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-XM-A8R8-01",
"age": 67,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-YT-A95D-01",
"age": 50,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-XU-A92W-01",
"age": 61,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-XU-A92X-01",
"age": 17,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-ZB-A96A-01",
"age": 53,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-XM-A8RG-01",
"age": 67,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-XU-A930-01",
"age": 43,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-ZB-A961-01",
"age": 69,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-XU-A92Q-01",
"age": 50,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-XU-A92O-01",
"age": 63,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-XU-A92Z-01",
"age": 76,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-XU-A92Y-01",
"age": 71,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-ZB-A965-01",
"age": 75,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-YT-A95F-01",
"age": 55,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-YT-A95H-01",
"age": 69,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-XU-AAXW-01",
"age": 39,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-ZB-A96E-01",
"age": 60,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-4V-A9QU-01",
"age": 76,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-ZB-A96B-01",
"age": 51,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-ZB-A969-01",
"age": 72,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-4V-A9QL-01",
"age": 58,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-4V-A9QJ-01",
"age": 64,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-5U-AB0E-01",
"age": 62,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-ZB-A96C-01",
"age": 77,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-ZC-AAAA-01",
"age": 39,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-ZC-AAAF-01",
"age": 74,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-5V-A9RR-01",
"age": 67,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-5U-AB0D-01",
"age": 71,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-3S-A8YW-01",
"age": 63,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-X7-A8D7-01",
"age": 46,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-3G-AB0T-01",
"age": 45,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-4V-A9QW-01",
"age": 62,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-X7-A8D9-01",
"age": null,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-4X-A9FD-01",
"age": 43,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-X7-A8DB-01",
"age": 71,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-X7-A8M4-01",
"age": 41,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-X7-A8M6-01",
"age": 43,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-4X-A9FA-01",
"age": 52,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-X7-A8M8-01",
"age": 45,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-4X-A9FC-01",
"age": 50,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-XH-A853-01",
"age": 67,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-ZC-AAAH-01",
"age": 52,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-XM-A8RI-01",
"age": 77,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-ZB-A96G-01",
"age": 59,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-ZC-AAA7-01",
"age": 63,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-3Q-A9WF-01",
"age": 71,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-ZB-A96R-01",
"age": 38,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-ZL-A9V6-01",
"age": 61,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-ZT-A8OM-01",
"age": 73,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-ZB-A964-01",
"age": 70,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-4V-A9QN-01",
"age": 40,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-XU-A936-01",
"age": 65,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-X7-A8M5-01",
"age": 65,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-ZB-A96V-01",
"age": 44,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-X7-A8M7-01",
"age": 26,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-XM-A8RH-01",
"age": 60,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-XM-A8RD-01",
"age": 69,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-XM-AAZ1-01",
"age": 42,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-XM-AAZ2-01",
"age": 73,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-XM-A8RL-01",
"age": 44,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-X7-A8DG-01",
"age": 47,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-XM-AAZ3-01",
"age": 64,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-X7-A8DJ-01",
"age": 68,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-XU-A92V-01",
"age": 72,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-XU-AAY1-01",
"age": 51,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-X7-A8DF-01",
"age": 40,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-XU-A932-01",
"age": 37,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-ZB-A96H-01",
"age": 73,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-X7-A8M0-01",
"age": 61,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-ZB-A96K-01",
"age": 69,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-ZB-A96O-01",
"age": 54,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-ZB-A96I-01",
"age": 71,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-XU-AAXY-01",
"age": 43,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-ZB-A96M-01",
"age": 56,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-ZB-A96L-01",
"age": 70,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-3G-AB19-01",
"age": 76,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-4V-A9QR-01",
"age": 51,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-XU-A931-01",
"age": 61,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-ZB-A966-01",
"age": 78,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-5G-A9ZZ-01",
"age": 52,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-X7-A8M3-01",
"age": 64,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-YT-A95G-01",
"age": 61,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-XU-AAY0-01",
"age": 61,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-XU-AAXX-01",
"age": 44,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-XU-A933-01",
"age": 52,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-XU-AAXZ-01",
"age": 63,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-X7-A8M1-01",
"age": 51,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-XU-A92T-01",
"age": 81,
"Cohort": "01. Tumortype: Thymoma"
},
{
"tissuename": "TCGA-XU-A92U-01",
"age": 67,
"Cohort": "01. Tumortype: Thymoma"
}
]
},
{
"name": "splitvalues",
"values": [],
"on": [
{
"trigger": "draggedMark",
"modify": "draggedMark",
"values": "dragTo"
},
{
"trigger": "addMark",
"insert": "addMark"
},
{
"trigger": "remMark",
"remove": "remMark"
}
]
},
{
"name": "data_0",
"source": "source_0",
"transform": [
{
"type": "kde",
"field": "age",
"groupby": [
"Cohort"
],
"counts": false,
"as": [
"value",
"density"
]
}
]
}
],
"signals": [
{
"name": "width",
"init": "isFinite(containerSize()[0]) ? containerSize()[0] : 200",
"on": [
{
"update": "isFinite(containerSize()[0]) ? containerSize()[0] : 200",
"events": "window:resize"
}
]
},
{
"name": "dragTo",
"on": [
{
"events": "[@right_grabber:mousedown, window:mouseup] > window:mousemove",
"update": "{x: invert('x',x())}"
}
]
},
{
"name": "draggedMark",
"on": [
{
"events": "@right_grabber:mousedown",
"update": "group().datum"
}
]
},
{
"name": "addMark",
"on": [
{
"events": [
{
"source": "view",
"type": "dblclick",
"filter": "item().mark.name === 'root'"
}
],
"update": "{x: invert('x',x())}"
}
]
},
{
"name": "remMark",
"on": [
{
"events": "@right_grabber:dblclick",
"update": "group().datum"
}
]
}
],
"marks": [
{
"name": "layer_0_marks",
"type": "line",
"style": [
"line"
],
"sort": {
"field": "datum['value']"
},
"from": {
"data": "data_0"
},
"encode": {
"update": {
"stroke": {
"value": "#4c78a8"
},
"description": {
"signal": "'density: ' + (format(datum['density'], '')) + '; Horsepower: ' + (format(datum['value'], ''))"
},
"x": {
"scale": "x",
"field": "value"
},
"y": {
"scale": "y",
"field": "density"
},
"defined": {
"signal": "isValid(datum['value']) && isFinite(+datum['value']) && isValid(datum['density']) && isFinite(+datum['density'])"
}
}
}
},
{
"name": "splitmarks",
"type": "group",
"from": {
"data": "splitvalues"
},
"encode": {
"enter": {
"height": {
"field": {
"group": "height"
}
}
},
"update": {
"x": [
{
"test": "!isValid(datum['x']) || !isFinite(+datum['x'])",
"value": 0
},
{
"scale": "x",
"field": "x"
}
]
}
},
"marks": [
{
"name": "layer_1_marks",
"type": "rule",
"style": [
"rule"
],
"encode": {
"update": {
"strokeDash": {
"value": [
4,
6
]
},
"stroke": {
"value": "black"
},
"y": {
"value": 0
},
"y2": {
"field": {
"group": "height"
}
}
}
}
},
{
"type": "path",
"name": "right_grabber",
"encode": {
"enter": {
"y": {
"field": {
"group": "height"
},
"mult": 0.5,
"offset": -50
},
"fill": {
"value": "#fff"
},
"stroke": {
"value": "#666"
},
"cursor": {
"value": "ew-resize"
}
},
"update": {
"path": {
"signal": "'M0.5,33.333333333333336A6,6 0 0 1 6.5,39.333333333333336V60.66666666666667A6,6 0 0 1 0.5,66.66666666666667ZM2.5,41.333333333333336V58.66666666666667M4.5,41.333333333333336V58.66666666666667'"
}
}
}
}
]
}
],
"scales": [
{
"name": "x",
"type": "linear",
"domain": {
"data": "data_0",
"field": "value"
},
"range": [
0,
{
"signal": "width"
}
],
"nice": true,
"zero": false
},
{
"name": "y",
"type": "linear",
"domain": {
"data": "data_0",
"field": "density"
},
"range": [
{
"signal": "height"
},
0
],
"nice": true,
"zero": true
}
],
"axes": [
{
"scale": "x",
"orient": "bottom",
"gridScale": "y",
"grid": true,
"title": "value, data",
"labelFlush": true,
"labelOverlap": true,
"tickCount": {
"signal": "ceil(width/40)"
},
"zindex": 0
},
{
"scale": "y",
"orient": "left",
"gridScale": "x",
"grid": true,
"title": "density",
"labelOverlap": true,
"tickCount": {
"signal": "ceil(height/40)"
},
"zindex": 0
}
],
"config": {
"range": {
"category": [
"#80b1d3"
]
},
"axis": {
"titleFontSize": 16,
"titleFontWeight": 500,
"titleFont": "Yantramanav",
"labelFontSize": 12,
"labelLimit": 150,
"labelFont": "Yantramanav",
"labelOverlap": "parity",
"labelSeparation": 5,
"labelBound": true
},
"legend": {
"titleFontSize": 16,
"titleFontWeight": 500,
"titleFont": "Yantramanav",
"labelFontSize": 12,
"labelLimit": 150,
"labelFont": "Yantramanav",
"labelOverlap": "parity"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment