如何在“ Vega Lite”的嵌套图表中共享标签?

发布于 2025-02-07 08:20:19 字数 2080 浏览 4 评论 0 原文

我想使用“ Vega Lite”来达到类似于Tableau的嵌套效果。尽管也可以实现“ Vega Lite”,但显示效果并不令人满意,这主要反映在每个子图中都有自己的坐标轴标签,并且信息密度不高。 Tableau更紧凑。

这是Tableau的一个例子:

这是Vega-Lite的一个示例:

{
  "data": {"url": "https://uniplore-source.oss-cn-chengdu.aliyuncs.com/other/orders2.csv"},
  "spacing": 0,
  "facet": {"row": {"field": "快递方式","type": "nominal",
   "header":{"labelExpr": "null"}
  }},

  "spec": {
    "facet": {"column": {"field": "类别","type": "nominal","header":{"labelExpr": "null"}}},
    "spacing": 0,
    "spec": {
      "spacing": 0,
      "facet": {
        "column": {
          "field": "子类别","type": "nominal"
        }
      },
      "spec": {
        "facet": {
          "column": {
            "field": "细分","type": "nominal"
          }
        },
        "spec": {
          "mark": "bar",
          "spacing": 0,
          "encoding": {
            "x": {
              "field": "细分","type": "nominal"
            },
            "y": {"aggregate": "sum","field":"销售额"}
          }
        }
      }
    }
  }
}

You can view my example here.

实际上,用Vega Lite在一个屏幕上不能显示相同数量的信息。

我尝试了一些配置,但是效果并不明显。

我想知道Vega Lite是否可以实现Tableau的显示效果。 其中最重要的是共享标签。

谢谢。

I want to use "Vega Lite" to achieve the faceted nesting effect similar to tableau. Although "Vega Lite" can also be achieved, the display effect is not satisfactory, which is mainly reflected in that each sub chart has its own coordinate axis label, and the information density is not high. Tableau is much more compact.

This is an example of tableau:
enter image description here

This is an example of vega-lite:
enter image description here

{
  "data": {"url": "https://uniplore-source.oss-cn-chengdu.aliyuncs.com/other/orders2.csv"},
  "spacing": 0,
  "facet": {"row": {"field": "快递方式","type": "nominal",
   "header":{"labelExpr": "null"}
  }},

  "spec": {
    "facet": {"column": {"field": "类别","type": "nominal","header":{"labelExpr": "null"}}},
    "spacing": 0,
    "spec": {
      "spacing": 0,
      "facet": {
        "column": {
          "field": "子类别","type": "nominal"
        }
      },
      "spec": {
        "facet": {
          "column": {
            "field": "细分","type": "nominal"
          }
        },
        "spec": {
          "mark": "bar",
          "spacing": 0,
          "encoding": {
            "x": {
              "field": "细分","type": "nominal"
            },
            "y": {"aggregate": "sum","field":"销售额"}
          }
        }
      }
    }
  }
}

You can view my example here.

In fact, the same amount of information can not be displayed on one screen with Vega Lite.

I have tried some configurations, but the effect is not obvious.

I want to know if there is any way Vega Lite can achieve the display effect of tableau.
The most important of these is shared labels.

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

流绪微梦 2025-02-14 08:20:19

如果您的意思是共享轴,则可以使用Facet进行此操作。

https://vega.github.io/vega.io/vega-lite/docs/docs/facet。 html

enter image description here

Edit 1

” =“ https://i.sstatic.net/gxwzh.png” alt =“在此处输入图像说明”>

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "name": "trellis_barley",
  "description": "The Trellis display by Becker et al. helped establish small multiples as a “powerful mechanism for understanding interactions in studies of how a response depends on explanatory variables”. Here we reproduce a trellis of Barley yields from the 1930s, complete with main-effects ordering to facilitate comparison.",
  "data": {"url": "data/barley.json"},
  "mark": "point",
  "height": {"step": 12},
  "encoding": {
    "facet": {
      "spacing": {"row": -40},
      "field": "site",
      "type": "ordinal",
      "columns": 2,
      "sort": {"op": "median", "field": "yield"},
      "header":{"labelExpr": "null"}
    },
    "x": {
      "aggregate": "median",
      "field": "yield",
      "type": "quantitative",
      "scale": {"zero": false}
    },
    "y": {"field": "variety", "type": "ordinal", "sort": "-x"},
    "color": {"field": "year", "type": "nominal"}
  }
}

If you mean shared axes, then you can do this using facet.

https://vega.github.io/vega-lite/docs/facet.html

enter image description here

Edit 1

Editor

enter image description here

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "name": "trellis_barley",
  "description": "The Trellis display by Becker et al. helped establish small multiples as a “powerful mechanism for understanding interactions in studies of how a response depends on explanatory variables”. Here we reproduce a trellis of Barley yields from the 1930s, complete with main-effects ordering to facilitate comparison.",
  "data": {"url": "data/barley.json"},
  "mark": "point",
  "height": {"step": 12},
  "encoding": {
    "facet": {
      "spacing": {"row": -40},
      "field": "site",
      "type": "ordinal",
      "columns": 2,
      "sort": {"op": "median", "field": "yield"},
      "header":{"labelExpr": "null"}
    },
    "x": {
      "aggregate": "median",
      "field": "yield",
      "type": "quantitative",
      "scale": {"zero": false}
    },
    "y": {"field": "variety", "type": "ordinal", "sort": "-x"},
    "color": {"field": "year", "type": "nominal"}
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文