looking for some solutions? You are welcome.

SOLVED: Incorrect axis position for grouped marks

Iain Dillingham:

I'd like to group axes and marks together within a group mark, as I'd like a bar chart to be one of several onto the data. However, when I do so the x axis moved from the bottom to the top of the bar chart. Here's an example:

{
  "$schema": "https://vega.github.io/schema/vega/v4.json",
  "width": 400,
  "height": 200,
  "padding": 5,
  "data": [
    {
      "name": "cars",
      "format": {
        "type": "json",
        "parse": {
          "year": "date"
        }
      },
      "url": "https://vega.github.io/vega-datasets/data/cars.json",
      "transform": [
        {
          "type": "aggregate",
          "groupby": [
            "Origin"
          ],
          "as": [
            "num_records"
          ]
        }
      ]
    }
  ],
  "scales": [
    {
      "name": "x",
      "type": "band",
      "domain": {
        "data": "cars",
        "field": "Origin"
      },
      "range": "width",
      "padding": 0.05
    },
    {
      "name": "y",
      "type": "linear",
      "domain": {
        "data": "cars",
        "field": "num_records"
      },
      "range": "height",
      "nice": true
    }
  ],
  "marks": [
    {
      "type": "group",
      "axes": [
        {
          "orient": "bottom",
          "scale": "x"
        },
        {
          "orient": "left",
          "scale": "y"
        }
      ],
      "marks": [
        {
          "type": "rect",
          "from": {
            "data": "cars"
          },
          "encode": {
            "enter": {
              "x": {
                "scale": "x",
                "field": "Origin"
              },
              "width": {
                "scale": "x",
                "band": 1
              },
              "y": {
                "scale": "y",
                "field": "num_records"
              },
              "y2": {
                "scale": "y",
                "value": 0
              }
            }
          }
        }
      ]
    }
  ]
}

The Group Mark documentation suggests that groups support such nested visualisation specifications. What am I doing wrong?



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
Share:

No comments:

Recent