{ "$schema": "https://vega.github.io/schema/vega/v5.json", "description": "Though Vega-Lite supports only one scale per axes, one can create a parallel coordinate plot by folding variables, using `joinaggregate` to normalize their values and using ticks and rules to manually create axes.", "background": "white", "padding": 5, "width": 600, "height": 300, "style": "cell", "data": [ { "name": "source_0", "url": "data/penguins.json", "format": {"type": "json"}, "transform": [ {"type": "filter", "expr": "datum['Beak Length (mm)']"}, { "type": "window", "params": [null], "as": ["index"], "ops": ["count"], "fields": [null], "sort": {"field": [], "order": []} }, { "type": "fold", "fields": [ "Beak Length (mm)", "Beak Depth (mm)", "Flipper Length (mm)", "Body Mass (g)" ], "as": ["key", "value"] }, { "type": "joinaggregate", "as": ["min", "max"], "ops": ["min", "max"], "fields": ["value", "value"], "groupby": ["key"] }, { "type": "formula", "expr": "(datum.value - datum.min) / (datum.max-datum.min)", "as": "norm_val" }, {"type": "formula", "expr": "(datum.min + datum.max) / 2", "as": "mid"} ] }, { "name": "data_0", "source": "source_0", "transform": [ { "type": "aggregate", "groupby": ["key"], "ops": ["min", "count", "max", "min"], "fields": ["min", null, "max", "mid"], "as": ["min_min", "__count", "max_max", "min_mid"] } ] } ], "marks": [ { "name": "layer_0_marks", "type": "rule", "style": ["rule"], "from": {"data": "data_0"}, "encode": { "update": { "stroke": {"value": "#ccc"}, "description": { "signal": "\"key: \" + (isValid(datum[\"key\"]) ? datum[\"key\"] : \"\"+datum[\"key\"]) + \"; Count of Records: \" + (format(datum[\"__count\"], \"\"))" }, "x": {"scale": "x", "field": "key", "band": 0.5}, "y": {"value": 0}, "y2": {"field": {"group": "height"}} } } }, { "name": "layer_1_pathgroup", "type": "group", "from": { "facet": { "name": "faceted_path_layer_1_main", "data": "source_0", "groupby": ["Species", "index"] } }, "encode": { "update": { "width": {"field": {"group": "width"}}, "height": {"field": {"group": "height"}} } }, "marks": [ { "name": "layer_1_marks", "type": "line", "style": ["line"], "sort": {"field": "datum[\"key\"]"}, "from": {"data": "faceted_path_layer_1_main"}, "encode": { "update": { "stroke": {"scale": "color", "field": "Species"}, "opacity": {"value": 0.3}, "tooltip": { "signal": "{\"Beak Length (mm)\": format(datum[\"Beak Length (mm)\"], \"\"), \"Beak Depth (mm)\": format(datum[\"Beak Depth (mm)\"], \"\"), \"Flipper Length (mm)\": format(datum[\"Flipper Length (mm)\"], \"\"), \"Body Mass (g)\": format(datum[\"Body Mass (g)\"], \"\")}" }, "description": { "signal": "\"key: \" + (isValid(datum[\"key\"]) ? datum[\"key\"] : \"\"+datum[\"key\"]) + \"; norm_val: \" + (format(datum[\"norm_val\"], \"\")) + \"; Species: \" + (isValid(datum[\"Species\"]) ? datum[\"Species\"] : \"\"+datum[\"Species\"]) + \"; index: \" + (isValid(datum[\"index\"]) ? datum[\"index\"] : \"\"+datum[\"index\"]) + \"; Beak Length (mm): \" + (format(datum[\"Beak Length (mm)\"], \"\")) + \"; Beak Depth (mm): \" + (format(datum[\"Beak Depth (mm)\"], \"\")) + \"; Flipper Length (mm): \" + (format(datum[\"Flipper Length (mm)\"], \"\")) + \"; Body Mass (g): \" + (format(datum[\"Body Mass (g)\"], \"\"))" }, "x": {"scale": "x", "field": "key", "band": 0.5}, "y": {"scale": "y", "field": "norm_val"}, "defined": { "signal": "isValid(datum[\"norm_val\"]) && isFinite(+datum[\"norm_val\"])" } } } } ] }, { "name": "layer_2_layer_0_marks", "type": "text", "style": ["text", "label"], "from": {"data": "data_0"}, "encode": { "update": { "fill": {"value": "black"}, "description": { "signal": "\"key: \" + (isValid(datum[\"key\"]) ? datum[\"key\"] : \"\"+datum[\"key\"]) + \"; Max of max: \" + (format(datum[\"max_max\"], \"\"))" }, "x": {"scale": "x", "field": "key", "band": 0.5}, "y": {"value": 0}, "text": {"signal": "format(datum[\"max_max\"], \"\")"} } } }, { "name": "layer_2_layer_1_marks", "type": "rect", "style": ["tick", "tick"], "from": {"data": "source_0"}, "encode": { "update": { "opacity": {"value": 0.7}, "fill": {"value": "#ccc"}, "ariaRoleDescription": {"value": "tick"}, "description": { "signal": "\"key: \" + (isValid(datum[\"key\"]) ? datum[\"key\"] : \"\"+datum[\"key\"])" }, "xc": {"scale": "x", "field": "key", "band": 0.5}, "yc": {"value": 0}, "width": {"value": 8}, "height": {"value": 1} } } }, { "name": "layer_3_layer_0_marks", "type": "text", "style": ["text", "label"], "from": {"data": "data_0"}, "encode": { "update": { "fill": {"value": "black"}, "description": { "signal": "\"key: \" + (isValid(datum[\"key\"]) ? datum[\"key\"] : \"\"+datum[\"key\"]) + \"; Min of mid: \" + (format(datum[\"min_mid\"], \"\"))" }, "x": {"scale": "x", "field": "key", "band": 0.5}, "y": {"value": 150}, "text": {"signal": "format(datum[\"min_mid\"], \"\")"} } } }, { "name": "layer_3_layer_1_marks", "type": "rect", "style": ["tick", "tick"], "from": {"data": "source_0"}, "encode": { "update": { "opacity": {"value": 0.7}, "fill": {"value": "#ccc"}, "ariaRoleDescription": {"value": "tick"}, "description": { "signal": "\"key: \" + (isValid(datum[\"key\"]) ? datum[\"key\"] : \"\"+datum[\"key\"])" }, "xc": {"scale": "x", "field": "key", "band": 0.5}, "yc": {"value": 150}, "width": {"value": 8}, "height": {"value": 1} } } }, { "name": "layer_4_layer_0_marks", "type": "text", "style": ["text", "label"], "from": {"data": "data_0"}, "encode": { "update": { "fill": {"value": "black"}, "description": { "signal": "\"key: \" + (isValid(datum[\"key\"]) ? datum[\"key\"] : \"\"+datum[\"key\"]) + \"; Min of min: \" + (format(datum[\"min_min\"], \"\"))" }, "x": {"scale": "x", "field": "key", "band": 0.5}, "y": {"value": 300}, "text": {"signal": "format(datum[\"min_min\"], \"\")"} } } }, { "name": "layer_4_layer_1_marks", "type": "rect", "style": ["tick", "tick"], "from": {"data": "source_0"}, "encode": { "update": { "opacity": {"value": 0.7}, "fill": {"value": "#ccc"}, "ariaRoleDescription": {"value": "tick"}, "description": { "signal": "\"key: \" + (isValid(datum[\"key\"]) ? datum[\"key\"] : \"\"+datum[\"key\"])" }, "xc": {"scale": "x", "field": "key", "band": 0.5}, "yc": {"value": 300}, "width": {"value": 8}, "height": {"value": 1} } } } ], "scales": [ { "name": "x", "type": "band", "domain": { "fields": [ {"data": "data_0", "field": "key"}, {"data": "source_0", "field": "key"} ], "sort": true }, "range": [0, {"signal": "width"}], "paddingInner": 0, "paddingOuter": 0 }, { "name": "y", "type": "linear", "domain": {"data": "source_0", "field": "norm_val"}, "range": [{"signal": "height"}, 0], "nice": true, "zero": true }, { "name": "color", "type": "ordinal", "domain": {"data": "source_0", "field": "Species", "sort": true}, "range": "category" } ], "axes": [ { "scale": "x", "orient": "bottom", "grid": false, "labelBaseline": "top", "zindex": 0 } ], "legends": [ { "stroke": "color", "symbolType": "stroke", "title": "Species", "encode": {"symbols": {"update": {"opacity": {"value": 0.3}}}} } ], "config": { "axisX": { "domain": false, "labelAngle": 0, "tickColor": "#ccc", "title": null }, "style": { "label": {"baseline": "middle", "align": "right", "dx": -5}, "tick": {"orient": "horizontal"}, "cell": {"stroke": null} } } }