当我尝试在类别之间创建空间并设置固定的类别顺序时,我陷入了在 Vega-Lite 中开发堆积条形图的困境。
因此,我不希望将类别(“资金收入”、“其他”、“费用”、“赚取收入”)混合在一起,而是希望每个类别之间留有一点空间。
此外,栏内的顺序应固定为:“资金收入”、“其他”、“费用”、“赚取收入”;但是,我无法使其正常工作。
有人可以帮忙吗? 谢谢”
这是一个示例:
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {
"values": [
{
"Year": 2022,
"Group": "Funding Income",
"Value": 7000,
"Type": "plan"
},
{
"Year": 2022,
"Group": "Earned Income",
"Value": 3000,
"Type": "plan"
},
{
"Year": 2022,
"Group": "Other",
"Value": 500,
"Type": "plan"
},
{
"Year": 2022,
"Group": "Expenses",
"Value": 8000,
"Type": "reality"
},
{
"Year": 2022,
"Group": "Other",
"Value": 1000,
"Type": "reality"
},
{
"Year": 2022,
"Group": "Funding Income",
"Value": 8000,
"Type": "reality"
},
{
"Year": 2021,
"Group": "Funding Income",
"Value": 6000,
"Type": "reality"
},
{
"Year": 2021,
"Group": "Other",
"Value": 700,
"Type": "reality"
},
{
"Year": 2021,
"Group": "Earned Income",
"Value": 3000,
"Type": "plan"
},
{
"Year": 2021,
"Group": "Other",
"Value": 1100,
"Type": "plan"
},
{
"Year": 2021,
"Group": "Funding Income",
"Value": 4000,
"Type": "plan"
},
{
"Year": 2021,
"Group": "Expenses",
"Value": 5000,
"Type": "reality"
}
]
},
"facet": {
"column": {
"field": "Year",
"type": "nominal",
"header": {
"labelOrient": "bottom",
"labelFont": "Arial black",
"labelColor": "black",
"title": null
}
}
},
"spec": {
"height": 164,
"layer": [
{
"mark": {
"type": "bar",
"cornerRadius": 1,
"stroke": "#363636",
"strokeWidth": 1.5
},
"encoding": {
"x": {
"field": "Type",
"axis": {
"labelAngle": 0,
"labelOffset": 0
},
"title": null
},
"y": {
"field": "Value",
"type": "quantitative",
"title": null
},
"xOffset": {"field": "Type"},
"color": {
"field": "Group",
"sort": [
"Funding Income",
"Other",
"Expenses",
"Earned Income"
],
"scale": {
"domain": [
"Funding Income",
"Other",
"Expenses",
"Earned Income"
],
"range": [
"gray",
"white",
"lightgray",
"black"
]
}
}
}
}
]
}
}
您是指这样的排序顺序吗?
如果是,请添加订单:
"order":{"sort": "descending", "field":"Group"},
关于堆栈之间的空间,这有点微妙。您可以:
如果你爆炸了,那么你就不能再有Y轴了,因为它没有意义。如果侵蚀,较小的值可能会消失。不管怎样,没有内置的功能可以做到这一点,但如果你想走爆炸路线,那么你可以从我的桑基示例中复制该技术,其中涉及引入空间的虚拟值:
https://github.com/PBI-David/Deneb-Showcase?tab=readme-ov-file#sankey-chart