Hi I have been following this tutorial and have it working on my own data, I would like to change the order of the columns but can't seem to figure it out or find any examples.
https://www.youtube.com/watch?v=2wZpdZ8hCik&t=466s
Say I have
ColA ColB ColC
and I would like
ColB ColC ColA
thanks for all ideas.
Solved! Go to Solution.
If you don't want to bring in an additional sort order field into deneb, you could implement a transform to do the sorting and then use it in the x encoding:
If this is enough to get you going, please consider kudoing and choosing this reply as the solution. If you need additional help, let me know.
Full spec:
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"width": {
"step": 30
},
"data": {
"url": "https://raw.githubusercontent.com/vega/vega-datasets/next/data/penguins.json"
},
"transform": [
{"window": [{"op": "row_number", "as": "row_num"}]},
{"filter": {"field": "row_num", "lte": "count"}},
{"fold": ["Flipper Length (mm)", "Species", "Island", "Sex"]},
{
"calculate": "datum['key'] == 'Species' ? 1 : datum['key'] == 'Sex' ? 2 : datum['key'] == 'Island' ? 3 : datum['key'] == 'Flipper Length (mm)' ? 4 : null", "as": "key_sort"
}
],
"mark": "text",
"encoding": {
"y": {"field": "row_num", "type": "ordinal", "axis": null},
"text": {"field": "value", "type": "nominal"},
"x": {"field": "key", "sort": {"field": "key_sort"},"type": "nominal", "axis": {"orient": "top", "labelAngle": 0, "title": null, "domain": false, "ticks": false}, "scale": {"padding": 15}}
}, "config": {"view": {"stroke": null}}
}
If you don't want to bring in an additional sort order field into deneb, you could implement a transform to do the sorting and then use it in the x encoding:
If this is enough to get you going, please consider kudoing and choosing this reply as the solution. If you need additional help, let me know.
Full spec:
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"width": {
"step": 30
},
"data": {
"url": "https://raw.githubusercontent.com/vega/vega-datasets/next/data/penguins.json"
},
"transform": [
{"window": [{"op": "row_number", "as": "row_num"}]},
{"filter": {"field": "row_num", "lte": "count"}},
{"fold": ["Flipper Length (mm)", "Species", "Island", "Sex"]},
{
"calculate": "datum['key'] == 'Species' ? 1 : datum['key'] == 'Sex' ? 2 : datum['key'] == 'Island' ? 3 : datum['key'] == 'Flipper Length (mm)' ? 4 : null", "as": "key_sort"
}
],
"mark": "text",
"encoding": {
"y": {"field": "row_num", "type": "ordinal", "axis": null},
"text": {"field": "value", "type": "nominal"},
"x": {"field": "key", "sort": {"field": "key_sort"},"type": "nominal", "axis": {"orient": "top", "labelAngle": 0, "title": null, "domain": false, "ticks": false}, "scale": {"padding": 15}}
}, "config": {"view": {"stroke": null}}
}
User | Count |
---|---|
117 | |
62 | |
60 | |
47 | |
40 |
User | Count |
---|---|
111 | |
63 | |
62 | |
51 | |
48 |