Mohit
Mohit

Reputation: 461

how i aligned grid lines in dual axis chart vegaLite

I am trying to create a dual axis chart in vegaLite ,when i make grid true for both layer then grid lines of y axis is not aligned i want align eqaully and provide better viz. for analysis. Editor link

For more clearification reference link in matplotlib

Upvotes: 1

Views: 91

Answers (1)

davidebacci
davidebacci

Reputation: 30304

You can manually set a domain. You would have to calculate these yourself though.

enter image description here

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "description": "A dual axis chart, created by setting y's scale resolution to `\"independent\"`",
  "width": 400,
  "height": 300,
  "data": {"url": "data/weather.csv"},
  "transform": [{"filter": "datum.location == \"Seattle\""}],
  "encoding": {
    "x": {
      "timeUnit": "month",
      "field": "date",
      "axis": {"format": "%b", "title": null}
    }
  },
  "layer": [
    {
      "mark": {"opacity": 0.3, "type": "area", "color": "#85C5A6"},
      "encoding": {
        "y": {
          "aggregate": "average",
          "field": "temp_max",
          "scale": {"domain": [0, 30]},
          "title": "Avg. Temperature (°C)",
          "axis": {"titleColor": "#85C5A6", "grid": true}
        },
        "y2": {"aggregate": "average", "field": "temp_min"}
      }
    },
    {
      "mark": {"stroke": "#85A9C5", "type": "line", "interpolate": "monotone"},
      "encoding": {
        "y": {
          "aggregate": "average",
          "field": "precipitation",
          "title": "Precipitation (inches)",
          "axis": {"titleColor": "#85A9C5", "grid": true}, "scale":{"domain":[0,6]}
        }
      }
    }
  ],
  "resolve": {"scale": {"y": "independent"}}
}

Upvotes: 1

Related Questions