Connected Scatterplot (Lines with Custom Paths)

A connected scatterplot can be created by customizing line order. Here we also use the shared encoding property of a layered plot.

View this example in the online editor

Vega-Lite JSON Specification

{
  "$schema": "https://vega.github.io/schema/vega-lite/v2.json",
  "data": {"url": "data/driving.json"},
  "encoding": {
    "x": {
      "field": "miles", "type": "quantitative",
      "scale": {"zero": false}
    },
    "y": {
      "field": "gas", "type": "quantitative",
      "scale": {"zero": false}
    }
  },
  "layer": [{
    "mark": "line",
    "encoding": {
      "order": {"field": "year","type": "temporal"}
    }
  }, {
    "mark": {"type": "point", "filled": true}
  }]
}