Skip to content

Instantly share code, notes, and snippets.

@dlaehnemann
Last active June 7, 2023 13:41
Show Gist options
  • Save dlaehnemann/1dfb721a830cb9fdb158784cdfb2553a to your computer and use it in GitHub Desktop.
Save dlaehnemann/1dfb721a830cb9fdb158784cdfb2553a to your computer and use it in GitHub Desktop.
horizontal stacked bar evidence plot with category selection
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"params": [
{
"name": "orientation",
"bind": {"input": "checkbox"}
},
{
"name": "strand",
"value": "true",
"bind": {"input": "checkbox"}
},
{
"name": "mapping_quality",
"bind": {"input": "checkbox"}
},
{
"name": "edit_distance",
"bind": {"input": "checkbox"}
},
],
"transform": [
{
"calculate": "[if(orientation, datum.orientation, null), if(mapping_quality, datum.quality, null), if(strand, datum.strand, null), if(edit_distance, datum['edit distance'], null)]",
"as": "split_array"
},
{
"calculate": "join(datum.split_array, '\t')",
"as": "categories"
},
{
"calculate": "indexof(['Very Strong (Alt)', 'Strong (Alt)', 'Positive (Alt)', 'Barely (Alt)', 'Equal', 'Barely (Ref)', 'Positive (Ref)', 'Strong (Ref)', 'Very Strong (Ref)'], datum.effect)",
"as": "order"
},
{
"calculate": "if(datum.effect === 'Very Strong (Ref)' || datum.effect === 'Strong (Ref)' || datum.effect === 'Positive (Ref)' || datum.effect === 'Barely (Ref)', datum.times, 0) + if(datum.effect === 'Equal', datum.times / 2, 0)",
"as": "offset"
},
{
"stack": "times",
"as": ["bar_start", "bar_end"],
"groupby": ["categories"],
"sort": [{
"field": "order",
"order": "descending"
}]
},
{
"joinaggregate": [
{
"field": "offset",
"op": "sum",
"as": "aggregated_offset"
}
],
"groupby": [ "categories" ]
},
{"calculate": "datum.bar_start - datum.aggregated_offset", "as": "bar_start_offset"},
{"calculate": "datum.bar_end - datum.aggregated_offset", "as": "bar_end_offset"}
],
"mark": "bar",
"encoding": {
"x": {
"field": "bar_start_offset",
"type": "quantitative",
"title": "Counts",
"axis": {
"labelExpr": "replace(datum.label, '−', '')"
}
},
"x2": {
"field": "bar_end_offset"
},
"y": {
"field": "categories",
"type": "nominal",
"title": "selected categories",
"axis": {
"ticks": false
}
},
"order": {"field": "order", "type": "quantitative", "sort": "descending"},
"color": {
"field": "effect",
"type": "ordinal",
"title": "Evidence",
"sort": {"field": "order", "order": "ascending"},
"scale": {
"domain": [
"Very Strong (Alt)",
"Strong (Alt)",
"Positive (Alt)",
"Barely (Alt)",
"Equal",
"Barely (Ref)",
"Positive (Ref)",
"Strong (Ref)",
"Very Strong (Ref)"
],
"range": [
"#ff5555",
"#ff6666",
"#ff9999",
"#ffcccc",
"#999999",
"#eaf7fb",
"#afdfee",
"#6cc5e0",
"#2dacd2"
]
}
},
"tooltip": [
{"field": "effect", "type": "nominal", "title": "Evidence"},
{"field": "strand", "type": "nominal", "title": "Strand"},
{"field": "orientation", "type": "nominal", "title": "Orientation"},
{"field": "times", "type": "quantitative", "title": "Counts"},
{"field": "edit distance", "type": "ordinal", "title": "Edit distance"}
]
},
"config": {"axisX": {"labelAngle": -30}},
"data": {
"values": [
{
"strand": "±",
"strand_orientation": "± unknown",
"effect": "Very Strong (Ref)",
"times": 70,
"quality": "high",
"orientation": "unknown",
"edit distance": "0"
},
{
"strand": "±",
"strand_orientation": "± F2R1",
"effect": "Very Strong (Ref)",
"times": 29,
"quality": "high",
"orientation": "F2R1",
"edit distance": "0"
},
{
"strand": "+",
"strand_orientation": "+ F2R1",
"effect": "Very Strong (Ref)",
"times": 20,
"quality": "high",
"orientation": "F2R1",
"edit distance": "0"
},
{
"strand": "-",
"strand_orientation": "- F2R1",
"effect": "Very Strong (Ref)",
"times": 13,
"quality": "high",
"orientation": "F2R1",
"edit distance": "0"
},
{
"strand": "±",
"strand_orientation": "± unknown",
"effect": "Very Strong (Ref)",
"times": 6,
"quality": "high",
"orientation": "unknown",
"edit distance": "0"
},
{
"strand": "±",
"strand_orientation": "± unknown",
"effect": "Very Strong (Alt)",
"times": 5,
"quality": "high",
"orientation": "unknown",
"edit distance": "0"
},
{
"strand": "-",
"strand_orientation": "- unknown",
"effect": "Very Strong (Ref)",
"times": 4,
"quality": "high",
"orientation": "unknown",
"edit distance": "0"
},
{
"strand": "-",
"strand_orientation": "- F1R2",
"effect": "Very Strong (Ref)",
"times": 6,
"quality": "high",
"orientation": "F1R2",
"edit distance": "0"
},
{
"strand": "-",
"strand_orientation": "- F2R1",
"effect": "Very Strong (Ref)",
"times": 4,
"quality": "high",
"orientation": "F2R1",
"edit distance": "0"
},
{
"strand": "+",
"strand_orientation": "+ F2R1",
"effect": "Very Strong (Ref)",
"times": 2,
"quality": "high",
"orientation": "F2R1",
"edit distance": "0"
},
{
"strand": "±",
"strand_orientation": "± F2R1",
"effect": "Very Strong (Ref)",
"times": 2,
"quality": "high",
"orientation": "F2R1",
"edit distance": "0"
},
{
"strand": "±",
"strand_orientation": "± F2R1",
"effect": "Very Strong (Ref)",
"times": 1,
"quality": "high",
"orientation": "F2R1",
"edit distance": "5"
},
{
"strand": "±",
"strand_orientation": "± F2R1",
"effect": "Very Strong (Ref)",
"times": 2,
"quality": "high",
"orientation": "F2R1",
"edit distance": "0"
},
{
"strand": "±",
"strand_orientation": "± unknown",
"effect": "Very Strong (Alt)",
"times": 1,
"quality": "high",
"orientation": "unknown",
"edit distance": "0"
},
{
"strand": "+",
"strand_orientation": "+ F2R1",
"effect": "Very Strong (Alt)",
"times": 1,
"quality": "high",
"orientation": "F2R1",
"edit distance": "0"
},
{
"strand": "±",
"strand_orientation": "± unknown",
"effect": "Very Strong (Ref)",
"times": 1,
"quality": "low",
"orientation": "unknown",
"edit distance": "0"
},
{
"strand": "±",
"strand_orientation": "± F2R1",
"effect": "Very Strong (Ref)",
"times": 1,
"quality": "low",
"orientation": "F2R1",
"edit distance": "0"
},
{
"strand": "±",
"strand_orientation": "± unknown",
"effect": "Barely (Ref)",
"times": 1,
"quality": "high",
"orientation": "unknown",
"edit distance": "0"
},
{
"strand": "±",
"strand_orientation": "± F2R1",
"effect": "Very Strong (Ref)",
"times": 1,
"quality": "high",
"orientation": "F2R1",
"edit distance": "2"
},
{
"strand": "+",
"strand_orientation": "+ F2R1",
"effect": "Barely (Alt)",
"times": 1,
"quality": "high",
"orientation": "F2R1",
"edit distance": "0"
},
{
"strand": "+",
"strand_orientation": "+ F2R1",
"effect": "Equal",
"times": 4,
"quality": "high",
"orientation": "F2R1",
"edit distance": "0"
},
{
"strand": "+",
"strand_orientation": "+ F2R1",
"effect": "Equal",
"times": 10,
"quality": "high",
"orientation": "F2R1",
"edit distance": "0"
},
{
"strand": "-",
"strand_orientation": "- F1R2",
"effect": "Equal",
"times": 5,
"quality": "high",
"orientation": "F1R2",
"edit distance": "0"
}
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment