Color Schemes
Color schemes provide a set of named color palettes for both discrete and continuous color encodings. Vega provides a collection of perceptually-motivated color schemes, many of which were originally created by Cynthia Brewer and the ColorBrewer project, or by Maureen Stone of Tableau Software. To view and set default color schemes, see the Config documentation.
Discrete color schemes may be used directly with scales that have discrete (or discretizing) domains, such as ordinal
, quantize
, and quantile
scales. Continuous color schemes can be used directly with continuous scales (such as linear
, log
, and sqrt
scales), and – by specifying a scheme count
property – can also be used to generate discrete color schemes.
Scheme Properties
Properties supported by color scheme definitions. These objects can be assigned to a scale’s range property. If a scale definition includes the property "reverse": true
, the color scheme order will be flipped.
Property | Type | Description |
---|---|---|
scheme | String | Color[ ] | Required. The name of the color scheme to use or an array of color values. See the scheme reference below for named schemes. For Vega 5.0 and higher, if a color array is provided, the colors will be interpolated to form a new scheme; use the scale interpolate property to set the interpolation type (defaults to linear RGB interpolation). |
count | Number | The number of colors to use in the scheme. This property can be useful for scale types such as quantile and quantize , which use the length of the scale range to determine the number of discrete bins for the scale domain. |
extent | Number[ ] | For continuous schemes only, determines the extent of the color range to use. For example [0.2, 1] will rescale the color scheme such that color values in the range [0, 0.2) are excluded from the scheme. Starting the extent array with the higher number will reverse the scheme order. For example, [1, 0] is the reverse of [0, 1] . |
Registering Additional Schemes
Vega can be extended with additional color schemes using the vega.scheme
method. New schemes must be a valid color array or interpolator. For example:
// Register a discrete color scheme named "basic" that can then be used in Vega specs
vega.scheme('basic', ['#f00', '#0f0', '#00f', '#ff0', '#f0f', '#0ff']);
// Register a custom continuous interpolation scheme
// Define an interpolator function that maps from [0,1] to colors
function grey(f) {
var g = Math.max(0, Math.min(255, Math.round(255 * f))) + '';
return 'rgb(' + g + ', ' + g + ', ' + g + ')';
}
// Register the interpolator. Now the scheme "mygrey" can be used in Vega specs
vega.scheme("mygrey", grey);
Scheme Reference
Categorical Schemes
Categorical color schemes can be used to encode discrete data values, each representing a distinct category.
Sequential Single-Hue Schemes
Sequential color schemes can be used to encode quantitative values. These color ramps are designed to encode increasing numeric values. Hover over a scheme and click the “View Discrete” link to toggle display of discretized palettes suitable for quantile, quantize, threshold, or ordinal scales.
Sequential Multi-Hue Schemes
Sequential color schemes can be used to encode quantitative values. These color ramps are designed to encode increasing numeric values, but use additional hues for more color discrimination, which may be useful for visualizations such as heatmaps. However, beware that using multiple hues may cause viewers to inaccurately see the data range as grouped into color-coded clusters. Hover over a scheme and click the “View Discrete” link to toggle display of discretized palettes suitable for quantile, quantize, threshold, or ordinal scales.
For Dark Backgrounds
For Light Backgrounds
Diverging Schemes
Diverging color schemes can be used to encode quantitative values with a meaningful mid-point, such as zero or the average value. Color ramps with different hues diverge with increasing saturation to highlight the values below and above the mid-point. Hover over a scheme and click the “View Discrete” link to toggle display of discretized palettes suitable for quantile, quantize, threshold, or ordinal scales.
Cyclical Schemes
Cyclical color schemes may be used to highlight periodic patterns in continuous data. However, these schemes are not well suited to accurately convey value differences.