如何在 Vega-Lite 中创建散点矩阵,其中 row/columns 由值(不是列名)标识
How to create scatter matrix in Vega-Lite where row/columns are identified by value (not column name)
我可以创建一个像 https://vega.github.io/editor/#/examples/vega-lite/interactive_splom 这样的散点矩阵吗?但是 column/rows 是根据分类值而不是列名创建的?
以下示例尝试根据高斯双变量分布中的 3 个值生成散点矩阵。但它只显示一行
{
"mark": "point",
"encoding": {
"x": {
"field": "value"
},
"y": {
"field": "value"
},
"row": {
"field": "coordinate"
},
"column": {
"field": "coordinate"
}
},
"data": {
"values": [
{
"value": -0.5600273,
"coordinate": 1
},
{
"value": -0.31220084,
"coordinate": 2
},
{
"value": -0.37932342,
"coordinate": 1
},
{
"value": -0.799277,
"coordinate": 2
},
{
"value": -1.8596855,
"coordinate": 1
},
{
"value": -3.100046,
"coordinate": 2
}
]
}
}
.
从您的数据中不清楚您希望在其他两个面板中出现什么。在绘制坐标 1 与坐标 2 时,哪些数据行会相互关联?
我假设您可以修改您的数据,使其具有第三个字段来指定哪些点放在一起;如果是这样,您可以使用 pivot transform to turn your values into columns, and then use the repeat operator as in the example you linked to (vega editor):
{
"data": {
"values": [
{"value": -0.5600273, "coordinate": 1, "point": 1},
{"value": -0.31220084, "coordinate": 2, "point": 1},
{"value": -0.37932342, "coordinate": 1, "point": 2},
{"value": -0.799277, "coordinate": 2, "point": 2},
{"value": -1.8596855, "coordinate": 1, "point": 3},
{"value": -3.100046, "coordinate": 2, "point":3}
]
},
"transform": [
{"pivot": "coordinate", "value": "value", "groupby": ["point"]}
],
"repeat": {"row": ["1", "2"], "column": ["1", "2"]},
"spec": {
"mark": "point",
"encoding": {
"x": {"field": {"repeat": "column"}, "type": "quantitative"},
"y": {"field": {"repeat": "row"}, "type": "quantitative"}
}
}
}
如果您不能将其添加到您的数据集中,而您只想将相邻值视为同一点的一部分,您可以使用一系列转换来指定这一点以构建 "point"
字段和恢复相同的图表(vega editor):
{
"data": {
"values": [
{"value": -0.5600273, "coordinate": 1},
{"value": -0.31220084, "coordinate": 2},
{"value": -0.37932342, "coordinate": 1},
{"value": -0.799277, "coordinate": 2},
{"value": -1.8596855, "coordinate": 1},
{"value": -3.100046, "coordinate": 2}
]
},
"transform": [
{"window": [{"op": "row_number", "as": "point"}]},
{"calculate": "ceil(datum.point / 2)", "as": "point"},
{"pivot": "coordinate", "value": "value", "groupby": ["point"]}
],
"repeat": {"row": ["1", "2"], "column": ["1", "2"]},
"spec": {
"mark": "point",
"encoding": {
"x": {"field": {"repeat": "column"}, "type": "quantitative"},
"y": {"field": {"repeat": "row"}, "type": "quantitative"}
}
}
}
我可以创建一个像 https://vega.github.io/editor/#/examples/vega-lite/interactive_splom 这样的散点矩阵吗?但是 column/rows 是根据分类值而不是列名创建的?
以下示例尝试根据高斯双变量分布中的 3 个值生成散点矩阵。但它只显示一行
{
"mark": "point",
"encoding": {
"x": {
"field": "value"
},
"y": {
"field": "value"
},
"row": {
"field": "coordinate"
},
"column": {
"field": "coordinate"
}
},
"data": {
"values": [
{
"value": -0.5600273,
"coordinate": 1
},
{
"value": -0.31220084,
"coordinate": 2
},
{
"value": -0.37932342,
"coordinate": 1
},
{
"value": -0.799277,
"coordinate": 2
},
{
"value": -1.8596855,
"coordinate": 1
},
{
"value": -3.100046,
"coordinate": 2
}
]
}
}
从您的数据中不清楚您希望在其他两个面板中出现什么。在绘制坐标 1 与坐标 2 时,哪些数据行会相互关联?
我假设您可以修改您的数据,使其具有第三个字段来指定哪些点放在一起;如果是这样,您可以使用 pivot transform to turn your values into columns, and then use the repeat operator as in the example you linked to (vega editor):
{
"data": {
"values": [
{"value": -0.5600273, "coordinate": 1, "point": 1},
{"value": -0.31220084, "coordinate": 2, "point": 1},
{"value": -0.37932342, "coordinate": 1, "point": 2},
{"value": -0.799277, "coordinate": 2, "point": 2},
{"value": -1.8596855, "coordinate": 1, "point": 3},
{"value": -3.100046, "coordinate": 2, "point":3}
]
},
"transform": [
{"pivot": "coordinate", "value": "value", "groupby": ["point"]}
],
"repeat": {"row": ["1", "2"], "column": ["1", "2"]},
"spec": {
"mark": "point",
"encoding": {
"x": {"field": {"repeat": "column"}, "type": "quantitative"},
"y": {"field": {"repeat": "row"}, "type": "quantitative"}
}
}
}
如果您不能将其添加到您的数据集中,而您只想将相邻值视为同一点的一部分,您可以使用一系列转换来指定这一点以构建 "point"
字段和恢复相同的图表(vega editor):
{
"data": {
"values": [
{"value": -0.5600273, "coordinate": 1},
{"value": -0.31220084, "coordinate": 2},
{"value": -0.37932342, "coordinate": 1},
{"value": -0.799277, "coordinate": 2},
{"value": -1.8596855, "coordinate": 1},
{"value": -3.100046, "coordinate": 2}
]
},
"transform": [
{"window": [{"op": "row_number", "as": "point"}]},
{"calculate": "ceil(datum.point / 2)", "as": "point"},
{"pivot": "coordinate", "value": "value", "groupby": ["point"]}
],
"repeat": {"row": ["1", "2"], "column": ["1", "2"]},
"spec": {
"mark": "point",
"encoding": {
"x": {"field": {"repeat": "column"}, "type": "quantitative"},
"y": {"field": {"repeat": "row"}, "type": "quantitative"}
}
}
}