# Field types and scales

> Nominal, ordinal, quantitative and temporal fields, and the scale settings for domain, zero, log and color ramps.

A channel's `type` picks its scale. These two charts plot the same 14 rows, one with `type: "ordinal"` on `x` and one with `type: "temporal"`.

```json
{
  "mark": {
    "type": "line",
    "stroke": "#0e7490",
    "strokeWidth": 2,
    "point": true
  },
  "data": [
    {
      "year": "1900",
      "anomaly": -0.08
    },
    {
      "year": "1910",
      "anomaly": -0.43
    },
    {
      "year": "1920",
      "anomaly": -0.27
    },
    {
      "year": "1930",
      "anomaly": -0.16
    },
    {
      "year": "1940",
      "anomaly": 0.12
    },
    {
      "year": "1950",
      "anomaly": -0.17
    },
    {
      "year": "1960",
      "anomaly": -0.03
    },
    {
      "year": "1970",
      "anomaly": 0.03
    },
    {
      "year": "1980",
      "anomaly": 0.26
    },
    {
      "year": "1990",
      "anomaly": 0.45
    },
    {
      "year": "2000",
      "anomaly": 0.39
    },
    {
      "year": "2010",
      "anomaly": 0.72
    },
    {
      "year": "2020",
      "anomaly": 1.01
    },
    {
      "year": "2025",
      "anomaly": 1.19
    }
  ],
  "encoding": {
    "x": {
      "field": "year",
      "type": "ordinal"
    },
    "y": {
      "field": "anomaly",
      "type": "quantitative",
      "axis": {
        "title": "Difference from the 1951–1980 average",
        "format": "+.1f",
        "labelSuffix": "°C"
      }
    }
  },
  "chrome": {
    "title": "On an ordinal axis, the five years from 2020 to 2025 get as much width as a decade",
    "subtitle": "Global surface temperature against the 1951–1980 average (°C), one reading per decade from 1900, then 2025"
  }
}
```

```json
{
  "mark": {
    "type": "line",
    "stroke": "#0e7490",
    "strokeWidth": 2,
    "point": true
  },
  "data": [
    {
      "year": "1900",
      "anomaly": -0.08
    },
    {
      "year": "1910",
      "anomaly": -0.43
    },
    {
      "year": "1920",
      "anomaly": -0.27
    },
    {
      "year": "1930",
      "anomaly": -0.16
    },
    {
      "year": "1940",
      "anomaly": 0.12
    },
    {
      "year": "1950",
      "anomaly": -0.17
    },
    {
      "year": "1960",
      "anomaly": -0.03
    },
    {
      "year": "1970",
      "anomaly": 0.03
    },
    {
      "year": "1980",
      "anomaly": 0.26
    },
    {
      "year": "1990",
      "anomaly": 0.45
    },
    {
      "year": "2000",
      "anomaly": 0.39
    },
    {
      "year": "2010",
      "anomaly": 0.72
    },
    {
      "year": "2020",
      "anomaly": 1.01
    },
    {
      "year": "2025",
      "anomaly": 1.19
    }
  ],
  "encoding": {
    "x": {
      "field": "year",
      "type": "temporal",
      "axis": {
        "format": "%Y"
      }
    },
    "y": {
      "field": "anomaly",
      "type": "quantitative",
      "axis": {
        "title": "Difference from the 1951–1980 average",
        "format": "+.1f",
        "labelSuffix": "°C"
      }
    }
  },
  "chrome": {
    "title": "Global temperature rose 1.16°C from 1970 to 2025",
    "subtitle": "Global surface temperature against the 1951–1980 average (°C), one reading per decade from 1900, then 2025"
  }
}
```

## Ordinal or temporal

An `ordinal` axis treats each year as a category and gives every one the same width, so the five years from 2020 to 2025 look as long as each decade before them. A `temporal` axis places each reading by its date, and the last segment shrinks to half a step. Use `temporal` whenever the values are dates; use `ordinal` for labels that are not dates, such as month names without a year or fiscal quarters.

## Zero and domain

```json
{
  "mark": {
    "type": "point",
    "trendline": false,
    "fill": "#0e7490",
    "size": 6
  },
  "data": [
    {
      "country": "India",
      "lifeExpectancy": 68.3
    },
    {
      "country": "China",
      "lifeExpectancy": 76.1
    },
    {
      "country": "United States",
      "lifeExpectancy": 79.2
    },
    {
      "country": "Indonesia",
      "lifeExpectancy": 69
    },
    {
      "country": "Brazil",
      "lifeExpectancy": 75.3
    },
    {
      "country": "Mexico",
      "lifeExpectancy": 76.9
    },
    {
      "country": "Japan",
      "lifeExpectancy": 83.6
    },
    {
      "country": "Germany",
      "lifeExpectancy": 80.8
    },
    {
      "country": "United Kingdom",
      "lifeExpectancy": 81.4
    },
    {
      "country": "France",
      "lifeExpectancy": 82.4
    },
    {
      "country": "South Korea",
      "lifeExpectancy": 81.9
    },
    {
      "country": "Canada",
      "lifeExpectancy": 82.2
    }
  ],
  "encoding": {
    "y": {
      "field": "country",
      "type": "nominal",
      "sort": "-x",
      "axis": {
        "values": [
          "India",
          "China",
          "United States",
          "Indonesia",
          "Brazil",
          "Mexico",
          "Japan",
          "Germany",
          "United Kingdom",
          "France",
          "South Korea",
          "Canada"
        ]
      }
    },
    "x": {
      "field": "lifeExpectancy",
      "type": "quantitative",
      "scale": {
        "zero": false,
        "domain": [
          65,
          85
        ]
      },
      "axis": {
        "title": "Life expectancy at birth (years)",
        "grid": true
      }
    }
  },
  "chrome": {
    "title": "Life expectancy runs from 68.3 years in India to 83.6 in Japan",
    "subtitle": "Life expectancy at birth in 12 large economies (years). The axis starts at 65."
  }
}
```

Whether a quantitative scale includes zero depends on the mark. Bars, areas and circles include it, because their length or position is read from the baseline. Line, point, beeswarm, range and text marks fit the data instead.

This dot plot uses `mark: { type: "point", trendline: false }`, which draws no stems, so an axis from 65 is fair and `scale: { zero: false, domain: [65, 85] }` fixes the range to the span that matters. Without `trendline: false`, a point mark fits a line through the dots. `circle` and `lollipop` draw a stem from zero to each dot, so keep zero for them, as on any bar or area chart.

## Log scale

```json
{
  "mark": {
    "type": "circle",
    "fill": "#0e7490",
    "size": 6
  },
  "data": [
    {
      "country": "India",
      "population": 1438.069596
    },
    {
      "country": "China",
      "population": 1410.71
    },
    {
      "country": "United States",
      "population": 336.806231
    },
    {
      "country": "Indonesia",
      "population": 281.190067
    },
    {
      "country": "Brazil",
      "population": 211.140729
    },
    {
      "country": "Mexico",
      "population": 129.739759
    },
    {
      "country": "Japan",
      "population": 124.51665
    },
    {
      "country": "Germany",
      "population": 83.287273
    },
    {
      "country": "United Kingdom",
      "population": 68.492
    },
    {
      "country": "France",
      "population": 68.372286
    },
    {
      "country": "South Korea",
      "population": 51.712619
    },
    {
      "country": "Canada",
      "population": 40.083484
    }
  ],
  "encoding": {
    "y": {
      "field": "country",
      "type": "nominal",
      "sort": "-x"
    },
    "x": {
      "field": "population",
      "type": "quantitative",
      "scale": {
        "type": "log",
        "domain": [
          30,
          1500
        ],
        "nice": false
      },
      "axis": {
        "title": "Population (millions, log scale)",
        "format": ",.0f",
        "values": [
          30,
          100,
          300,
          1000
        ],
        "grid": true
      }
    }
  },
  "chrome": {
    "title": "India has about 36 times as many people as Canada",
    "subtitle": "Population of 12 large economies, 2023 (millions). Equal distances on the axis are equal ratios."
  }
}
```

`scale: { type: "log" }` spaces values by ratio, so the gap from 30 to 300 million equals the gap from 100 million to 1 billion. On a linear axis, India and China would sit far to the right and the other ten countries would crowd into the left quarter. `axis.values` picks round ticks, and the axis title says "log scale" so no reader takes the spacing as linear.

## Sequential color

```json
{
  "mark": "rect",
  "data": [
    {
      "year": "2016",
      "source": "Coal",
      "share": 31.2
    },
    {
      "year": "2016",
      "source": "Gas",
      "share": 34.8
    },
    {
      "year": "2016",
      "source": "Nuclear",
      "share": 20.3
    },
    {
      "year": "2016",
      "source": "Hydro",
      "share": 6.6
    },
    {
      "year": "2016",
      "source": "Wind",
      "share": 5.7
    },
    {
      "year": "2016",
      "source": "Solar",
      "share": 1.4
    },
    {
      "year": "2017",
      "source": "Coal",
      "share": 30.7
    },
    {
      "year": "2017",
      "source": "Gas",
      "share": 33
    },
    {
      "year": "2017",
      "source": "Nuclear",
      "share": 20.5
    },
    {
      "year": "2017",
      "source": "Hydro",
      "share": 7.5
    },
    {
      "year": "2017",
      "source": "Wind",
      "share": 6.5
    },
    {
      "year": "2017",
      "source": "Solar",
      "share": 2
    },
    {
      "year": "2018",
      "source": "Coal",
      "share": 28.2
    },
    {
      "year": "2018",
      "source": "Gas",
      "share": 36
    },
    {
      "year": "2018",
      "source": "Nuclear",
      "share": 19.8
    },
    {
      "year": "2018",
      "source": "Hydro",
      "share": 7
    },
    {
      "year": "2018",
      "source": "Wind",
      "share": 6.7
    },
    {
      "year": "2018",
      "source": "Solar",
      "share": 2.3
    },
    {
      "year": "2019",
      "source": "Coal",
      "share": 23.9
    },
    {
      "year": "2019",
      "source": "Gas",
      "share": 39.2
    },
    {
      "year": "2019",
      "source": "Nuclear",
      "share": 20
    },
    {
      "year": "2019",
      "source": "Hydro",
      "share": 7
    },
    {
      "year": "2019",
      "source": "Wind",
      "share": 7.3
    },
    {
      "year": "2019",
      "source": "Solar",
      "share": 2.6
    },
    {
      "year": "2020",
      "source": "Coal",
      "share": 19.6
    },
    {
      "year": "2020",
      "source": "Gas",
      "share": 41.3
    },
    {
      "year": "2020",
      "source": "Nuclear",
      "share": 20.1
    },
    {
      "year": "2020",
      "source": "Hydro",
      "share": 7.1
    },
    {
      "year": "2020",
      "source": "Wind",
      "share": 8.6
    },
    {
      "year": "2020",
      "source": "Solar",
      "share": 3.3
    },
    {
      "year": "2021",
      "source": "Coal",
      "share": 22.2
    },
    {
      "year": "2021",
      "source": "Gas",
      "share": 39
    },
    {
      "year": "2021",
      "source": "Nuclear",
      "share": 19.3
    },
    {
      "year": "2021",
      "source": "Hydro",
      "share": 6.1
    },
    {
      "year": "2021",
      "source": "Wind",
      "share": 9.3
    },
    {
      "year": "2021",
      "source": "Solar",
      "share": 4.1
    },
    {
      "year": "2022",
      "source": "Coal",
      "share": 19.9
    },
    {
      "year": "2022",
      "source": "Gas",
      "share": 40.4
    },
    {
      "year": "2022",
      "source": "Nuclear",
      "share": 18.5
    },
    {
      "year": "2022",
      "source": "Hydro",
      "share": 6
    },
    {
      "year": "2022",
      "source": "Wind",
      "share": 10.4
    },
    {
      "year": "2022",
      "source": "Solar",
      "share": 4.9
    },
    {
      "year": "2023",
      "source": "Coal",
      "share": 16.2
    },
    {
      "year": "2023",
      "source": "Gas",
      "share": 43.5
    },
    {
      "year": "2023",
      "source": "Nuclear",
      "share": 18.6
    },
    {
      "year": "2023",
      "source": "Hydro",
      "share": 5.8
    },
    {
      "year": "2023",
      "source": "Wind",
      "share": 10.1
    },
    {
      "year": "2023",
      "source": "Solar",
      "share": 5.8
    }
  ],
  "encoding": {
    "x": {
      "field": "year",
      "type": "nominal"
    },
    "y": {
      "field": "source",
      "type": "nominal"
    },
    "color": {
      "field": "share",
      "type": "quantitative",
      "scale": {
        "scheme": "blues"
      },
      "format": ".1f"
    }
  },
  "chrome": {
    "title": "Gas rose as coal's share halved",
    "subtitle": "Share of US electricity generation by source (%), 2016-2023. Darker cells = larger share."
  }
}
```

On `rect` heatmaps and point marks, a `quantitative` field on `color` gets a sequential scale. Bars do not shade by a quantitative color field yet, so give them a `condition` instead, as the [encoding page](/docs/the-spec/encoding/) does. `scheme` names the ramp: `blue`, `green`, `orange`, `purple` or `teal`, with Vega-Lite names such as `blues` accepted. Add `domain` to fix the ends, for example `[0, 100]` for a share, so two heatmaps of the same measure use the same colors.

## Fields that matter

| Field | What it does |
| --- | --- |
| `type` | `quantitative`, `temporal`, `nominal` or `ordinal`. Picks the default scale. |
| `scale.type` | Overrides the scale, for example `"log"`, `"sqrt"` or `"symlog"`. |
| `scale.zero` | Whether a quantitative domain includes zero. On by default for bar, area and circle marks; off for line, point, beeswarm, range and text. |
| `scale.domain` | Fixed `[min, max]` for continuous scales, or the category list for categorical ones. |
| `scale.nice` | Rounds the domain out to clean tick values. Default true. |
| `scale.scheme` | A named color ramp for the color channel. |
| `scale.range` | Explicit output values, such as exact colors. Wins over `scheme`. |

## Related

- [Heatmap](/docs/correlation/heatmap/) uses sequential color on a grid.
- [Line](/docs/change-over-time/line/) shows a log scale on a growth series.
- [Axes](/docs/the-spec/axes/) covers tick formats and gridlines.
- [Encoding reference](/docs/spec/encoding/) lists every scale option.
