Vega-lite: Boxplot with repeat

Created on 19 Nov 2018  路  4Comments  路  Source: vega/vega-lite

This may be related to #2655.

I don't seem to be able to use boxplots with "repeated" specifications. Both these specs work if I use a "tick" mark instead of a "boxplot" mark; the second (with repeat) does not work for boxplots.

Thanks!


This works for both "tick" and "boxplot":

{
  "$schema": "https://vega.github.io/schema/vega-lite/v3.json",
  "data": {
    "url": "https://vega.github.io/vega-datasets/data/cars.json"
  },
  "mark": "boxplot",
  "encoding": {
    "x": {
      "field": "Cylinders",
      "type": "ordinal"
    },
    "y": {
      "field": "Acceleration",
      "type": "quantitative"
    }
  }
} 

However, this does work for "tick" but not for "boxplot":

{
  "$schema": "https://vega.github.io/schema/vega-lite/v3.json",
  "data": {
    "url": "https://vega.github.io/vega-datasets/data/cars.json"
  },
  "repeat": {
    "column": [
      "Acceleration",
      "Displacement",
      "Horsepower"
    ]
  },
  "spec": {
    "mark": "boxplot",
    "encoding": {
      "x": {
        "field": "Cylinders",
        "type": "ordinal"
      },
      "y": {
        "field": {
          "repeat": "column"
        },
        "type": "quantitative"
      }
    }
  }
} 
Area - Macro / Composite Mark Blocked Bug

All 4 comments

I'm getting an error in the Vega expression parsing. We need to look into what gets generated incorrectly.

When normalizing error bar spec:

{
  "$schema": "https://vega.github.io/schema/vega-lite/v3.json",
  "data": {
    "url": "https://vega.github.io/vega-datasets/data/cars.json"
  },
  "repeat": {
    "column": [
      "Acceleration",
      "Displacement"
    ]
  },
  "spec": {
    "mark": "errorbar",
    "encoding": {
      "y": {
        "field": {
          "repeat": "column"
        },
        "type": "quantitative"
      }
    }
  }
}

it produces:

{
  "$schema": "https://vega.github.io/schema/vega-lite/v3.json",
  "data": {"url": "https://vega.github.io/vega-datasets/data/cars.json"},
  "repeat": {"column": ["Acceleration", "Displacement"]},
  "spec": {
    "transform": [
      {
        "aggregate": [
          {
            "op": "stderr",
            "field": {"repeat": "column"},
            "as": "extent_[object Object]"
          },
          {
            "op": "mean",
            "field": {"repeat": "column"},
            "as": "center_[object Object]"
          }
        ],
        "groupby": []
      },
      {
        "calculate": "datum[\"center_[object Object]\"] + datum[\"extent_[object Object]\"]",
        "as": "upper_[object Object]"
      },
      {
        "calculate": "datum[\"center_[object Object]\"] - datum[\"extent_[object Object]\"]",
        "as": "lower_[object Object]"
      }
    ],
    "layer": [
      {
        "mark": {"type": "rule", "style": "errorbar-rule"},
        "encoding": {
          "y": {
            "field": "lower_[object Object]",
            "type": "quantitative",
            "title": {"repeat": "column"}
          },
          "y2": {"field": "upper_[object Object]", "type": "quantitative"},
          "tooltip": [
            {
              "field": "center_[object Object]",
              "type": "quantitative",
              "title": "Mean of [object Object]"
            },
            {
              "field": "upper_[object Object]",
              "type": "quantitative",
              "title": "Mean + stderr of [object Object]"
            },
            {
              "field": "lower_[object Object]",
              "type": "quantitative",
              "title": "Mean - stderr of [object Object]"
            }
          ]
        }
      }
    ]
  }
}

We assume that field is a string. But using repeat, field is an object instead which cause the error.

This is because the boxplot macro needs actual field to apply it expansion, but it won't know until repeat is performed first. However, currently repeat is not applied during normalization, but rather during model initialization. Thus, it might be impossible to achieve this solution without refactoring
repeat to be a macro instead of an internal model class (#4947).

Since we reimplement repeat as macro, this is now working in VL 4.8.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kanitw picture kanitw  路  4Comments

domoritz picture domoritz  路  3Comments

domoritz picture domoritz  路  4Comments

mcnuttandrew picture mcnuttandrew  路  3Comments

kanitw picture kanitw  路  3Comments