Vega lite:有两个独立的数据集和独立的过滤器
Vega lite: having two separate datasets with separate filters
我想知道如何在 vega lite 中拥有一种 hconcat,但有两个独立的数据集。我想让前 10 个值和后 10 个值在不同约束条件下彼此相邻显示,但我在使用过滤器时遇到问题。
可以在图表的任何级别指定数据和转换,并在适用时将它们向下传递到子图表。这是改编自 Filtering Top K Items in the example gallery, which applies a different filter to each concatenated chart (view in editor) 的示例:
{
"data": {
"values": [
{"student": "A", "score": 100},
{"student": "B", "score": 56},
{"student": "C", "score": 88},
{"student": "D", "score": 65},
{"student": "E", "score": 45},
{"student": "F", "score": 23},
{"student": "G", "score": 66},
{"student": "H", "score": 67},
{"student": "I", "score": 13},
{"student": "J", "score": 12},
{"student": "K", "score": 50},
{"student": "L", "score": 78},
{"student": "M", "score": 66},
{"student": "N", "score": 30},
{"student": "O", "score": 97},
{"student": "P", "score": 75},
{"student": "Q", "score": 24},
{"student": "R", "score": 42},
{"student": "S", "score": 76},
{"student": "T", "score": 78},
{"student": "U", "score": 21},
{"student": "V", "score": 46}
]
},
"transform": [
{
"window": [{"op": "rank", "as": "rank"}],
"sort": [{"field": "score", "order": "descending"}]
}
],
"vconcat": [
{
"transform": [{"filter": "datum.rank <= 3"}],
"mark": "bar",
"encoding": {
"x": {"field": "score", "type": "quantitative"},
"y": {
"field": "student",
"type": "nominal",
"sort": {"field": "score", "op": "average", "order": "descending"}
}
}
},
{
"transform": [{"filter": "datum.rank > 19"}],
"mark": "bar",
"encoding": {
"x": {"field": "score", "type": "quantitative"},
"y": {
"field": "student",
"type": "nominal",
"sort": {"field": "score", "op": "average", "order": "descending"}
}
}
}
]
}
类似地,如果你想在每个子图中使用不同的数据源,你可以在子图中指定 "data"
属性。
我想知道如何在 vega lite 中拥有一种 hconcat,但有两个独立的数据集。我想让前 10 个值和后 10 个值在不同约束条件下彼此相邻显示,但我在使用过滤器时遇到问题。
可以在图表的任何级别指定数据和转换,并在适用时将它们向下传递到子图表。这是改编自 Filtering Top K Items in the example gallery, which applies a different filter to each concatenated chart (view in editor) 的示例:
{
"data": {
"values": [
{"student": "A", "score": 100},
{"student": "B", "score": 56},
{"student": "C", "score": 88},
{"student": "D", "score": 65},
{"student": "E", "score": 45},
{"student": "F", "score": 23},
{"student": "G", "score": 66},
{"student": "H", "score": 67},
{"student": "I", "score": 13},
{"student": "J", "score": 12},
{"student": "K", "score": 50},
{"student": "L", "score": 78},
{"student": "M", "score": 66},
{"student": "N", "score": 30},
{"student": "O", "score": 97},
{"student": "P", "score": 75},
{"student": "Q", "score": 24},
{"student": "R", "score": 42},
{"student": "S", "score": 76},
{"student": "T", "score": 78},
{"student": "U", "score": 21},
{"student": "V", "score": 46}
]
},
"transform": [
{
"window": [{"op": "rank", "as": "rank"}],
"sort": [{"field": "score", "order": "descending"}]
}
],
"vconcat": [
{
"transform": [{"filter": "datum.rank <= 3"}],
"mark": "bar",
"encoding": {
"x": {"field": "score", "type": "quantitative"},
"y": {
"field": "student",
"type": "nominal",
"sort": {"field": "score", "op": "average", "order": "descending"}
}
}
},
{
"transform": [{"filter": "datum.rank > 19"}],
"mark": "bar",
"encoding": {
"x": {"field": "score", "type": "quantitative"},
"y": {
"field": "student",
"type": "nominal",
"sort": {"field": "score", "op": "average", "order": "descending"}
}
}
}
]
}
类似地,如果你想在每个子图中使用不同的数据源,你可以在子图中指定 "data"
属性。