Vega lite 顶部和底部 10

Vega lite top and bottom 10

我想知道是否可以在 vega lite 中同时显示顶部和底部的 10 个对象(定量)。

我知道如何单独获取它们,但不知道如何同时获取它们:

 "transform": [
    {
      "window": [{"op": "rank", "as": "rank"}],
      "sort": [{"field": "Days_to_maturity", "order": "descending"}]
    },
    {"filter": "datum.rank <= 10"}
  ],

是的,你可以这样做:

  "transform": [
    {
      "window": [{"op": "rank", "as": "rank"}],
      "sort": [{"field": "Days_to_maturity", "order": "descending"}]
    },
    {"joinaggregate": [{"op": "max", "field": "rank", "as": "total"}]}
    {"filter": "(datum.rank <= 10) || (datum.rank > datum.total - 10)"}
  ],

请注意,rank 聚合将为相同的值赋予相同的排名,因此如果您的数据中存在重复值,这可能不会在每一端准确显示 10。如果只想显示前 10 行和后 10 行而不考虑重复项,可以将 count window 更改为 ignorePeers:

  "transform": [
    {
      "window": [{"op": "count", "as": "rank"}],
      "sort": [{"field": "Days_to_maturity", "order": "descending"}],
      "ignorePeers": true
    },
    {"joinaggregate": [{"op": "max", "field": "rank", "as": "total"}]},
    {"filter": "(datum.rank <= 10) || (datum.rank > datum.total - 10)"}
  ],

您可以在 Window Transform docs 中找到有关 window 转换选项的更多详细信息。