The Vega scales
property maps visually encoded data values to pixel positions with attributes, such as color. See the D3 scales documentation for additional background information about scales.
General scales
property JSON format:
"scales": [{"name": <scaleID>,"type": <scaleType>,"domain": <inputValues>,"range": <outputValues>""accumulator": <accumulatorType>"default": <defaultOutputValue>,"nullValue": <nullDataValue>},{...}],
The scales specification is one or more arrays with the following properties:
Property Field  Data Type  Required  Description 
â€‹  string  X  Userdefined scale name. 
â€‹  string  â€‹  Scale type, which specifies the

â€‹  array  â€‹  Domain. Array of input interval data values. 
â€‹  string or array  â€‹  Range. Array of output interval visual data values. 
â€‹  number  â€‹  Default output value to use when domain value does not map to range value. 
â€‹  string  â€‹  Accumulation rendering type:

 number  â€‹  Specify the output value to use when the input value is 
Note: As a general rule, limit the total number of domain and range values used to a maximum of 1000. Exceeding this limit can cause an error.
Define two scales, x
and y
. For the x
scale, linearly transform input data values between 100
and 999
to the visualization area width
. For the y
scale, linearly transform input data values between 0
and 500
to the visualization area height
. The width
and height
range values are predefined literals that reference the width
and height
properties.
vegaSpec = {width: 384,height: 564,data: [ ... elided ... ],scales: [{name: "x",type: "linear",domain: [ 100, 999 ],range: "width"},{name: "y",type: "linear",domain: [ 0, 500 ],range: "height"}],marks: [ ... elided ... ]};
The name property uniquely identifies the scale for reference by other properties.
The type property specifies how to transform the input, domain data to output, range visual values. Vega supports the following transforms, categorized by quantitative, discrete, and discretizing scales:
Type  Description  Additional Information 
 Preserves proportional differences, where range value y can be expressed as a linear function of the domain value  â€‹D3 linear scaleâ€‹ 
 Applies a logarithmic transform to the input domain value before the output range value is computed. The mapping to the range value y can be expressed as a logarithmic function of the domain value x: As
 â€‹D3 logarithmic scaleâ€‹ 
 Applies an exponential transform to the input domain value before the output range value is computed. Range value y can be expressed as a polynomial function of the domain value x: Default exponent =  â€‹D3 power scaleâ€‹ 
 A shorthand for power scales with an exponent of 0.5, indicating a square root transform.
 â€‹D3 sqrt scaleâ€‹ 
Type  Description  Resource 
 Applies a discrete domaintorange transform, and functions as a lookup table from a domain value to a range value. Specify a default value for domain values that do not map to a range.  â€‹D3 ordinal scaleâ€‹ 
Type  Description  Resource 
 Divides input domain values into uniform segments based on the number of values in, or the cardinality of, the output range, where range value y can be expressed as a quantized linear function of the domain value x:  â€‹D3 quantize scaleâ€‹ 
 Maps arbitrary, nonuniform subsets of the domain to discrete range values. The input domain is continuous but divided into slices based on a set of domain threshold values. The range must have N+1 elements, where N is the number of domain threshold boundaries.  â€‹D3 threshold scaleâ€‹ 
The domain
field specifies the domain of input data values. For quantitative data, this can take the form of a twoelement array.
Specify minimum and maximum input values.
domain: [ 100, 999 ]
For ordinal or categorical data, the domain can be an array of valid input values.
Specify valid input data languages.
"domain": ["en", "es", "fr"]
Scale range specifies the set of visual values. For numeric values, the range can take the form of a twoelement array with minimum and maximum values. For ordinal or quantized data, the range can be an array of desired output values, which are mapped to elements in the specified domain.
Scale ranges can be specified in the following ways:
As an array of static values: "range": [0, 500]
or "range": ['a', 'b', 'c']
.
Using predefined literals: "range": "width"
or "range": "height"
.
Specify a color scale that quantizes input values between 0
and 100
among five visual output colors.
{name: "color",type: "quantize",domain: [ 0, 100 ],range: [ "#115f9a", "#1984c5", "#c9e52f", "#d0ee11", "#d0f400"]}
Scale ranges can accept width
and height
string literals that map to the Width and Height Properties.
Value  Description 
 A spatial range that is the value of t``width``. 
 A spatial range that is the value of 
Specify a y
scale that linearly maps input values between 0
and 500
to the height of the visualization area.
{name: "y",type: "linear",domain: [ 0, 500 ],range: "height"}
The default
scales property specifies the output value to use when the input domain value does not map to the range.
The default
property is not applicable to the threshold
scale type, which maps domain values outside of the range to either the lowest or highest range value.
The accumulator property enables you to identify regional density of data in a layer of a backend render and apply pixel coloring based on the accumulation mode that you have defined. Each data point is rendered individually, providing an accurate representation of data distribution in a spatial setting.
Mode  Description 
 Perform count aggregation per pixel and define a color for a pixel by normalizing the count and applying a color to it based on a color scale. You can activate density accumulation for any scale that takes as input a continuous domain (linear, sqrt, pow, log, threshold scales) and outputs a color range. The range is determined by the required
Note: Domain values of 
 Blend by category (ultimately an ordinal scale). You can provide a color to a category and blend those colors to show the density of the distinct categorical values at a pixel. 
 For a specific category, apply color based on the percentage of the category in a region. 
Apply a density accumulator to a linear scale named pointcolor
:
{"name": "pointcolor","type": "linear","domain": [0.0,1.0],"range": ["blue","red"],"clamp": true,"accumulator": "density","minDensityCnt": 1,"maxDensityCnt": 100}
The color at a pixel is determined by normalizing perpixel aggregated counts and using that value in the scale function to calculate a color. Normalization is performed according to the required minDensityCnt
and maxDensityCnt
properties. After normalization, minDensityCnt
== 0
and maxDensityCnt
== 1
.
minDensityCnt
and maxDensityCnt
can have explicit integer values or use one of the following keywords to compute statistical information about perpixel counts: min
, max
, 1stStdDev
, 2ndStdDev
, 1stStdDev
, 2ndStdDev
.
For more detailed examples of using accumulators, see Tutorial: Vega Accumulator.