// Single View Specification{ "data": ... , "mark": "errorbar", "encoding": ... , ...}
An error bar summarizes an error range of quantitative values using a set of summary statistics, representing by rules (and optional end ticks). Error bars in Vega-Lite can either be used to aggregate raw data or directly visualize aggregated data.
To create an error bar, setmark
to"errorbar"
.
An error bar’s mark definition contain the following properties:
Property | Type | Description |
---|---|---|
type | ErrorBar | Required. The mark type. This could a primitive mark type (one of |
extent | String | The extent of the rule. Available options include:
Default value: |
orient | String | Orientation of the error bar. This is normally automatically determined, but can be specified when the orientation is ambiguous and cannot be automatically determined. |
color | Color |Gradient |ExprRef | Default color. Default value:■ Note:
|
opacity | Number | The opacity (value between [0,1]) of the mark. |
Besides the properties listed above,rule
andticks
can be used to specify the underlyingmark properties for differentparts of the error bar as well.
If the data is not aggregated yet, Vega-Lite will aggregate the data based on theextent
properties in the mark definition.
extent
to"stderr"
. The length of lower and upper rules represent standard error. By default, the rule marks expand from the mean.extent
to"stdev"
. For this type of error bar, the length of lower and upper rules represent standard deviation. Like an error bar that shows Standard Error, the rule marks expand from the mean by default.extent
to"ci"
. For this type of error bar, the rule marks expand from the"ci0"
value to"ci1"
value, as defined inaggregate.extent
to"iqr"
. For this type of error bar, the rule marks expand from the first quartile to the third quartile.If the data is already pre-aggregated with low and high values of the error bars, you can directly specifyx
andx2
(ory
andy2
) to use error bar as a ranged mark.
If the data is already pre-aggregated with center and error values of the error bars, you can directly specityx
as center,xError
andxError2
as error values extended from center (ory
,yError
, andyError2
). Ifx/yError2
is omitted, error bars have symmetric error values.
Error bar with symmetric error values:
Error bar with asymmetric error values:
Note if error is pre-aggregated with asymmetric error values one ofx/yError
andx/yError2
has to be positive value and other has to be negative value
Vega-Lite supports both 1D and 2D error bars:
{:#1d} A1D error bar shows the error range of a continuous field.
The orientation of an error bar is automatically determined by the continuous field axis. For example, you can create a vertical 1D error bar by encoding a continuous field on the y axis.
{:#2d} A2D error bar shows the error range of a continuous field, broken down by categories.
For 2D error bars with one continuous field and one discrete field, the error bars will be horizontal if the continuous field is on the x axis.
Alternatively, if the continuous field is on the y axis, the error bar will be vertical.
Under the hood, theerrorbar
mark is acomposite mark that expands into a layered plot. For example,a basic 1D error bar shown above is expanded to:
We can customize different parts of the error barmark definition orconfig.
For example, we can add the error bar’s end ticks and customize it by settingticks
totrue
or adding a mark property toticks
, such as settingcolor
to"teal"
:
You can customize the color, size, and opacity of the bar in theerrorbar
by using thecolor
, andopacity
encoding channels, which applied to the wholeerrorbar
.
Here is an example of aerrorbar
with thecolor
encoding channel set to{"value": "#4682b4"}
.
You can add custom tooltips to error bars. The custom tooltip will override the default error bar’s tooltips.
{ "errorbar": { "extent": ..., "rule": ..., "ticks": ... }}
Theerrorbar
config object sets the default properties forerrorbar
marks.
The error bar config can contain allerror bar mark properties but currently does not supportcolor
,opacity
, andorient
. Please see issue#3934 for details.