Skip to content

The Vega-Lite Visualization Library (vega-lite)

Vega-Lite Visualization Library

Module: vegalite

View source
vegalite

Module containing a function to display a relation R as a Vega-Lite chart, if supported by the client, as well as convenience functions for constructing relations to be plotted.

Display function

  • plot[R]: Given a relation representing a full JSON Vega-Lite schema, richly render it as a Vega-Lite chart. See the Vega-Lite docs (opens in a new tab) for more information on creating a Vega-Lite schema.

Convenience functions

The convenience functions build upon the vegalite_utils and templates to provide a simpler interface to generate common plot types. All convenience functions take in required arguments for that type of plot, along with a CONFIG relation, which includes the data. They each output a JSON relation, which can then be plotted with the plot display function, or further modified by overloading the relation or overriding specific values (see right_override).

  • bar[X, Y, CONFIG]: Given an X relation specifying the x field (categorical data), a Y relation specifying the y field (quantitative data), and a CONFIG relation (see the section on CONFIG below), gives a relation specifying a bar chart in vegalite.
  • scatter[X, Y, CONFIG]: Given an X relation specifying the x field (quantitative data), a Y relation specifying the y field (quantitative data), and a CONFIG relation (see the section on CONFIG below), gives a relation specifying a scatter chart in vegalite.
  • line[X, Y, CONFIG]: Given an X relation specifying the x field (quantitative data), a Y relation specifying the y field (quantitative data), and a CONFIG relation (see the section on CONFIG below), gives a relation specifying a scatter chart in vegalite.

The convenience functions generally combine encoding functions from vegalite_utils along with other utilities with the corresponding vegalite_templates template. The CONFIG relation requires the (:data, DATA) tuple at a minimum, but can also include tuples with any vegalite_utils utility name and its arguments (e.g. (:width, 500), (:x, :axis, :orient, "top"))

Examples

Specify a full JSON Relation

def chart[:data, :values, :[]] = {
  (1, :a, "A");
  (1, :b, 28);
  (2, :a, "B");
  (2, :b, 55);
  (3, :a, "C");
  (3, :b, 43)
}
def chart[:mark, :type] = "bar"
def chart[:mark, :tooltip] = boolean_true // Note: JSON `boolean_true` / `boolean_false`
def chart[:encoding, :x] = {
  (:field, "a");
  (:type, "nominal");
  (:axis, :labelAngle, 0)
}
def chart[:encoding, :y] = {
  (:field, "b");
  (:type, "quantitative")
}
 
def output = vegalite:plot[chart]

Outputs the custom Rel Vega-Lite MIME type along with the chart relation tuples, for the plot to be rendered by Vega-Lite in a client.

Note: JSON-value relations require boolean_true / boolean_false values in tuples (e.g. setting :tooltip to boolean_false), not the logical true / false used in Formulas. Logical true / false cannot be used as values.

Read in JSON example then add data

def chart = parse_json[\"\"\"{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "description": "A simple bar chart with embedded data.",
  "mark": {"type": "bar", "tooltip": false},
  "encoding": {
    "x": {"field": "a", "type": "nominal", "axis": {"labelAngle": 0}},
    "y": {"field": "b", "type": "quantitative"}
  }
}\"\"\"]
 
def data = {("A", 28); ("B", 55); ("C", 43)}
def chart[:data][:values][:[]][i] =
  {(:a, a); (:b, b)} from a,b where enumerate[data](i, a, b)
 
def output = vegalite:plot[chart]

Combines the Vega-Lite JSON specification without data, with data defined in Rel. Outputs the custom Rel Vega-Lite MIME type along with the chart relation tuples.

Simple bar chart

def data:letter = {(1, "A"); (2, "B"); (3, "C")}
def data:number = {(1, 24); (2, 67); (3, 43)}
 
def chart = vegalite:bar[:letter, :number, {:data, data}]
def output = vegalite:plot[chart]

The data is defined in the (field, keys..., value) format (same format used by load_csv), and then plotted with the categorical letter field on the x axis and the quantitative number field on the y axis.

Complex bar chart from CSV data

// penguin dataset
def file_config[:path] = "azure://raidocs.blob.core.windows.net/ml-classification/penguin/penguins_size.csv"
 
def file_config[:schema, :species] = "string"
def file_config[:schema, :island] = "string"
def file_config[:schema, :culmen_length_mm] = "float"
def file_config[:schema, :culmen_depth_mm] = "float"
def file_config[:schema, :flipper_length_mm] = "float"
def file_config[:schema, :body_mass_g] = "float"
def file_config[:schema, :sex] = "string"
 
def chart_config:data = lined_csv[load_csv[file_config]]
def chart_config:color = {(:sex); (:title, "Sex"); (:scale, :schema, "dark2")}
def chart_config:y = {:title, "Count of Penguins"}
def chart_config:title = "🐧"
 
def chart = vegalite:bar[
  :species,
  {:aggregate, "count"},
  chart_config
]
 
def output = vegalite:plot[chart]

Outputs a stacked barchart of the count of penguins broken down by species (bar height) and sex (color within each bar).

The x axis field is set using the fieldname :species.

The {:aggregate, "count"} is using aggregate encoding (opens in a new tab) to plot the number of records for each :species on the y axis instead of a field directly.

The :color encoding is doing three things:

  1. Creating the stacking of the bar chart by coloring each bar by the :sex breakdown within each :species, grouping the chart data by :sex.
  2. The (:color, :title) is being set to "Sex", which will update the title of the legend (included by default) as well as the field name displayed in the tooltip (included with the vegalite_templates:bar relation).
  3. The color scheme is being changed from the default ("tableau10") to the "dark2" scheme. See the Vega documentation (opens in a new tab) for the full list of color schemes available.

The (:y, :title, "Count of Penguins") relation is setting the title of the y axis to "Count of Penguins". This also updates the field name displayed in the tooltip.

The (:title, "🐧") relation sets a title for the chart.

Checkout the vega library.

See Also

Module: vegalite_utils and Module: vegalite_templates.

plot

View source
plot[R]

Combine the Vega-Lite schema relation R with the Vega-Lite MIME type to be richly rendered by the client.

bar

View source
bar[X, Y, CONFIG]

Construct a Vega-Lite specification for a bar chart.

Arguments

  • X: A relation specifying the x field in the chart. Typically, a RelName (e.g. :category) will be passed to indicate the field in the :data to use as the x data. By default, this is set to “nominal” (opens in a new tab) data (i.e. categorical) and the chart’s bars are sorted in ascending order by the value of this field. Can accept any values accepted by the :x encoding channel (opens in a new tab).
  • Y: A relation specifying the y field in the chart. Typically, a RelName (e.g. :amount) will be passed to indicate the field in the :data to use as the y data. An :aggregate (opens in a new tab) tuple might be used in addition to the field specified by a RelName (in the case of a "mean" of that field), or instead of the field (in the case of a "count" of records). By default, this is set to “quantitative” (opens in a new tab) data. Can accept any values accepted by the :y encoding channel (opens in a new tab).
  • CONFIG: An overloaded relation with configuration for the chart. At a minimum, must contain the (:data, DATA) tuple, where DATA is a relation in the column-wise format (field, keys..., value). Any tuple in the CONFIG relation can contain the name of a utility from vegalite_utils along with the arguments to that utility.

Examples

Simple bar chart

def data:letter = {(1, "A"); (2, "B"); (3, "C")}
def data:number = {(1, 24); (2, 67); (3, 43)}
 
def chart = vegalite:bar[:letter, :number, {:data, data}]
def output = vegalite:plot[chart]

The data is defined in the (field, keys..., value) format (same format used by load_csv), and then plotted with the categorical letter field on the x axis and the quantitative number field on the y axis.

Complex bar chart from CSV data

// penguin dataset
def file_config[:path] = "azure://raidocs.blob.core.windows.net/ml-classification/penguin/penguins_size.csv"
 
def file_config[:schema, :species] = "string"
def file_config[:schema, :island] = "string"
def file_config[:schema, :culmen_length_mm] = "float"
def file_config[:schema, :culmen_depth_mm] = "float"
def file_config[:schema, :flipper_length_mm] = "float"
def file_config[:schema, :body_mass_g] = "float"
def file_config[:schema, :sex] = "string"
 
def chart_config:data = lined_csv[load_csv[file_config]]
def chart_config:color = {(:sex); (:title, "Sex"); (:scale, :schema, "dark2")}
def chart_config:y = {:title, "Count of Penguins"}
def chart_config:title = "🐧"
 
def chart = vegalite:bar[
  :species,
  {:aggregate, "count"},
  chart_config
]
 
def output = vegalite:plot[chart]

Outputs a stacked barchart of the count of penguins broken down by species (bar height) and sex (color within each bar).

The x axis field is set using the fieldname :species.

The {:aggregate, "count"} is using aggregate encoding (opens in a new tab) to plot the number of records for each :species on the y axis instead of a field directly.

The :color encoding is doing three things:

  1. creating the stacking of the bar chart by coloring each bar by the :sex breakdown within each :species.
  2. The :title is being set to "Sex", which will update the title of the legend (included by default) as well as the field name displayed in the tooltip (included with the vegalite_templates:bar relation).
  3. The color scheme is being changed from the default ("tableau10") to the "dark2" scheme. See the vega documentation (opens in a new tab) for the full list of color schemes available.

The (:y, :title, "Count of Penguins") relation is setting the title of the y axis to "Count of Penguins". This also updates the field name displayed in the tooltip.

The (:title, "🐧") relation sets a title for the chart.

Simple bar chart with entity data

entity Country
country_from_name = {
    "United States";
    "France";
    "Iceland";
}
 
def country:name(e, value) = country_from_name(value, e)
 
def country:population[e in country_from_name["Iceland"]] = 364134
def country:population[e in country_from_name["United States"]] = 328239523
def country:population[e in country_from_name["France"]] = 2931241
 
def chart = vegalite:bar[
  :name,
  :population,
  {:data, country}
]
def output = vegalite:plot[chart]

Outputs a bar chart with the country name on the x axis and the population on the y axis.

Horizontal bar chart sorted by value

def data:letter = {(1, "A"); (2, "B"); (3, "C")}
def data:number = {(1, 24); (2, 67); (3, 43)}
 
def chart = vegalite:bar[
  :number,
  :letter,
  {
    (:data, data);
    (:x, :type, "quantitative");
    (:y, :type, "nominal");
    (:sort, "-x")
  }
]
def output = vegalite:plot[chart]

Outputs a bar chart with horizontal bars of letter on the y axis vs number on the x axis. The bars are sorted by the x value (number) in descending order.

scatter

View source
scatter[X, Y, CONFIG]

Construct a Vega-Lite specification for a scatter plot.

Arguments

  • X: A relation specifying the x field in the chart. Typically, a RelName (e.g. :height) will be passed to indicate the field in the :data to use as the x data. By default, this is set to “quantitative” (opens in a new tab) data (i.e. categorical). Can accept any values accepted by the :x encoding channel (opens in a new tab).
  • Y: A relation specifying the y field in the chart. Typically, a RelName (e.g. :wingspan) will be passed to indicate the field in the :data to use as the y data. An :aggregate (opens in a new tab) tuple might be used in addition to the field specified by a RelName (in the case of a "mean" of that field), or instead of the field (in the case of a "count" of records). By default, this is set to “quantitative” (opens in a new tab) data. Can accept any values accepted by the :y encoding channel (opens in a new tab).
  • CONFIG: An overloaded relation with configuration for the chart. At a minimum, must contain the (:data, DATA) tuple, where DATA is a relation in the column-wise format (field, keys..., value). Any tuple in the CONFIG relation can contain the name of a utility from vegalite_utils along with the arguments to that utility.

Examples

Simple scatter plot

def data:height = {(1, 102); (2, 94); (3, 74)}
def data:wingspan = {(1, 36.2); (2, 45.2); (3, 35.0)}
 
def chart = vegalite:scatter[:height, :wingspan, {:data, data}]
 
def output = vegalite:plot[chart]

The data is defined in the (field, keys..., value) format (same format used by load_csv), and then plotted with the quantitative height field on the x axis and the quantitative wingspan field on the y axis.

Complex scatter plot from CSV data

Translated from the Colored Scatterplot Vega-Lite example (opens in a new tab).

// penguin dataset
def file_config[:path] = "azure://raidocs.blob.core.windows.net/ml-classification/penguin/penguins_size.csv"
 
def file_config[:schema, :species] = "string"
def file_config[:schema, :island] = "string"
def file_config[:schema, :culmen_length_mm] = "float"
def file_config[:schema, :culmen_depth_mm] = "float"
def file_config[:schema, :flipper_length_mm] = "float"
def file_config[:schema, :body_mass_g] = "float"
def file_config[:schema, :sex] = "string"
 
def chart_config:data = lined_csv[load_csv[file_config]]
def chart_config:color = :species
def chart_config:shape = :species
def chart_config:x = {(:title, "Flipper Length (mm)"); (:scale, :zero, boolean_false)}
def chart_config:y = {(:title, "Body Mass (g)"); (:scale, :zero, boolean_false)}
def chart_config:title = "🐧"
 
def chart = vegalite:scatter[
  :flipper_length_mm,
  :body_mass_g,
  chart_config
]
 
def output = vegalite:plot[chart]

Outputs a scatter plot of flipper length vs body mass with the points colored and shaped by the species. A legend and tooltip are included by default.

The X and Y relations are simply the field names in the dataset in :data, data.

The :species is double encoded with the :color and :shape property channels (opens in a new tab). Each species is assigned a unique shape and color, which are shown in the legend. This has the effect of grouping-by species in the plot.

Both the x and y axes have custom titles set (the default is the field name) and neither includes zero in its domain (opens in a new tab).

The (:title, "🐧") relation sets a title for the chart.

Set custom axis range

def data:height = {(1, 102); (2, 94); (3, 74)}
def data:wingspan = {(1, 36.2); (2, 45.2); (3, 35.0)}
 
def chart = vegalite:scatter[
  :height,
  :wingspan,
  {
    :data, data;
    :x, :scale, :domain, :[], {(1, 50); (2, 150)}
  }
]
 
def output = vegalite:plot[chart]

Output a scatter plot with the x axis from 50 to 150 instead of from zero to the field’s maximum (the default).

line

View source
line[X, Y, CONFIG]

Construct a Vega-Lite specification for a line chart.

Arguments

  • X: A relation specifying the x field in the chart. Typically, a RelName (e.g. :year) will be passed to indicate the field in the :data to use as the x data. By default, this is set to “quantitative” (opens in a new tab) data (i.e. categorical). Can accept any values accepted by the :x encoding channel (opens in a new tab).
  • Y: A relation specifying the y field in the chart. Typically, a RelName (e.g. :price) will be passed to indicate the field in the :data to use as the y data. An :aggregate (opens in a new tab) tuple might be used in addition to the field specified by a RelName (in the case of a "mean" of that field), or instead of the field (in the case of a "count" of records). By default, this is set to “quantitative” (opens in a new tab) data. Can accept any values accepted by the :y encoding channel (opens in a new tab).
  • CONFIG: An overloaded relation with configuration for the chart. At a minimum, must contain the (:data, DATA) tuple, where DATA is a relation in the column-wise format (field, keys..., value). Any tuple in the CONFIG relation can contain the name of a utility from vegalite_utils along with the arguments to that utility.

Examples

Simple line plot

def data:year = {(1, 1990); (2, 2000); (3, 2010)}
def data:price = {(1, 36.2); (2, 45.2); (3, 74.0)}
 
def chart = vegalite:line[:year, :price, {:data, data}]
 
def output = vegalite:plot[chart]

The data is defined in the (field, keys..., value) format (same format used by load_csv), and then plotted with the quantitative year field on the x axis and the quantitative price field on the y axis.

Multi-line, colored line plot

// penguin dataset
def file_config[:path] = "azure://raidocs.blob.core.windows.net/ml-classification/penguin/penguins_size.csv"
 
def file_config[:syntax, :header_row] = -1
def file_config[:syntax, :header] =
    (1, :frequency);
    (2, :angle);
    (3, :chord_length);
    (4, :velocity) ;
    (5, :displacement) ;
    (6, :sound)
 
def file_config[:syntax, :delim] = '\t'
 
def file_config[:schema, :frequency] = "float"
def file_config[:schema, :angle] = "float"
def file_config[:schema, :chord_length] = "float"
def file_config[:schema, :velocity] = "float"
def file_config[:schema, :displacement] = "float"
def file_config[:schema, :sound] = "float"
 
def chart_config:data = lined_csv[load_csv[file_config]]
def chart_config:color = {(:chord_length); (:title, "Chord Length")}
def chart_config:strokeWidth = {(:velocity); (:type, "nominal")}
def chart_config:opacity = 0.8
def chart_config:y = {:scale, :zero, boolean_false}
 
def chart = vegalite:line[
  :angle,
  {:sound; :aggregate, "mean"},
  chart_config
]
 
def output = vegalite:plot[chart]

Outputs a line plot of angle vs sound with the lines colored by chord_length and strokeWidth’ed by velocity. A legend and tooltip are included by default.

The X relation is simply the field names in the dataset in (:data, data). The Y relation is both a field name and an (:aggregate, "mean"), which sets the y axis to be the mean of the field :sound instead of the raw data points. The mean is grouped by both :chord_length and :velocity due to the :color and :strokeWidth encodings.

The :color relation sets a custom title, which displays on the legend and the tooltip (included by default with the vegalite_templates:line relation).

The :opacity of the lines is set to 0.8, making it easier to distinguish the densely clustered lines.

The :y encoding sets (:scale, :zero, boolean_false) so that the zero point is not included in the axis, which is the default for quantitative data.

Module: vegalite_templates

View source vegalite_templates

Contains partial specifications to be used as templates for creating common types of Vega-Lite charts:

  • bar: A bar chart with the categorical data on the x axis and quantitative on the y
  • scatter: A scatter plot with quantitative data on both axes
  • line: A line chart with quantitative date on both axes

bar

View source
bar

Partial specification for a Vega-Lite bar chart

Example

def data:letter = {(1, "A"); (2, "B"); (3, "C")}
def data:number = {(1, 24); (2, 67); (3, 43)}
 
def chart = vegalite_utils:x[:letter]
def chart = vegalite_utils:y[:number]
def chart = vegalite_utils:data[data]
def chart = vegalite_templates:bar
 
def output = vegalite:plot[chart]

Outputs a bar chart with the letters on the x axis and the numbers on the y axis. The axis titles match the field names and a tooltip is included in the template.

scatter

View source
scatter

Partial specification for a Vega-Lite scatter plot

Example

def data:height = {(1, 102); (2, 94); (3, 74)}
def data:wingspan = {(1, 36.2); (2, 45.2); (3, 35.0)}
 
def chart = vegalite_utils:x[:height]
def chart = vegalite_utils:y[:wingspan]
def chart = vegalite_utils:data[data]
def chart = vegalite_templates:scatter
 
def output = vegalite:plot[chart]

Outputs a scatter plot with the height on the x axis and the wingspan on the y axis and each (height, wingspan) pair is a point on the chart. The axis titles match the field names and a tooltip is included in the template.

line

View source
line

Partial specification for a Vega-Lite line chart

Example

def data:year = {(1, 1990); (2, 2000); (3, 2010)}
def data:price = {(1, 36.2); (2, 45.2); (3, 74.0)}
 
def chart = vegalite_utils:x[:year]
def chart = vegalite_utils:y[:price]
def chart = vegalite_utils:data[data]
def chart = vegalite_templates:line
 
def output = vegalite:plot[chart]

Outputs a line plot with the year on the x axis and the price on the y axis and each (year, price) pair is connected by a line on the chart. The axis titles match the field names and a tooltip is included in the template.

Module: vegalite_utils

View source
vegalite_utils

Utility functions for building Vega-Lite specifications. Most functions correspond to either a top-level or encoding key in the Vega-Lite specification.

data

View source
data[DATA]

Takes the overloaded relation DATA with the column-wise format (field, keys…, value) and adds the values as an array in the top-level data key.

The field is expected to be a RelName (e.g. :price), the keys... and value can be any type except for RelName.

Gives a relation that defines inline data (opens in a new tab) for the Vega-Lite spec.

Examples

(field, key, value) data

def data:year = {(1, 1990); (2, 2000); (3, 2010)}
def data:price = {(1, 36.2); (2, 45.2); (3, 74.0)}
 
def output = vegalite_utils:data[data]

Outputs the data organized as (position, field, value) and prepended with the keys :data, :values, :[].

(field, keys..., value) data

def data:year = {(1, 1990); (2, 2000); (3, 2010)}
def data:price = {(1, "shoes", 36.2); (2, "coats", 45.2); (3, "ties", 74.0)}
 
def output = vegalite_utils:data[data]

Outputs the data organized as (position, field, value) and prepended with the keys :data, :values, :[].

(field, entity, value) data

entity Country
country_from_name = {
    "United States";
    "France";
    "Iceland";
}
 
def country:name(e, value) = country_from_name(value, e)
 
def country:population[e in country_from_name["Iceland"]] = 364134
def country:population[e in country_from_name["United States"]] = 328239523
def country:population[e in country_from_name["France"]] = 2931241
 
def output = vegalite_utils:data[country]

Outputs the data organized as (position, field, value) and prepended with the keys :data, :values, :[].

(key, field, value) data (row-wise)

def data = {
  1, {(:year, 1990); (:price, 36.2)};
  2, {(:year, 2000); (:price, 45.2)};
  3, {(:year, 2010); (:price, 74.0)};
}
 
def output = vegalite_utils:data[{field, key, value : data(key, field, value)}]

Outputs the data organized as (position, field, value) and prepended with the keys :data, :values, :[].

Instead of reordering the fields to pass them to vegalite_utils:data, this data could also be prepended with (:data, :values, :[]) as it is already in the required format.

title

View source
title[t]
title[CONFIG]

Add the string t as a title (opens in a new tab) for the Vega-Lite chart. Or provide an overloaded relation CONFIG with keys and values as described in the Vega-Lite docs (opens in a new tab) (e.g. :color).

Gives a relation that is the string t prepended with the keys :title, and :text and any binary tuples prepended with :title.

Examples

Add a basic title

def output = vegalite_utils:title["A Simple Title"]

Outputs {:title, :text, "A Simple Title"}, which adds the title to the top center of the chart in black font.

Add a fancy title

def output = vegalite_utils:title[{
  ("Fancy Title");
  (:subtitle, "Fancy Titles require Fancy Subtitles");
  (:color, "purple");
  (:anchor, "start");
  (:fontSize, 24);
  (:fontStyle, "italic");
  (:subtitleColor, "blue");
}]

Outputs "Fancy Title" prepended by :title', :textand the other tuples prepended only with:title`. This would add a purple title and a blue subtitle with italic, size 24 font which was anchored at the top left of the chart.

width

View source
width[w]

Set the width (opens in a new tab) of the Vega-Lite chart in pixels. Gives w prepended with the :width key.

height

View source
height[h]

Set the height (opens in a new tab) of the Vega-Lite chart in pixels. Gives h prepended with the :height key.

background

View source
background[c]

Set the background color (opens in a new tab) of the entire Vega-Lite chart to c. Gives c prepended with the :background key.

x

View source
x[:field_name]
x[value]
x[CONFIG]

Set the encoding for the x position channel (opens in a new tab). If CONFIG is a unary RelName, the value is assumed to be a field name and is prepended with (:encoding, :x, :field). If CONFIG is any other unary value, it is assumed to be a value and is prepended with (:encoding, :x, :value). Any tuples with arity >= 2 are prepended with (:encoding, :x).

Examples

Set x to a field

def output = vegalite_utils:x[:my_field]

Outputs (:encoding, :x, :field, "my_field"). By default, the field name is then used as the axis title on the x axis.

Set x to a value

def output = vegalite_utils:x[202]

Outputs (:encoding, :x, :value, 200). This is less commonly used compared to defining x with a field, but can be useful when adding a vertical line to a chart.

Set x to a field and set some options

def output = vegalite_utils:x[{
  (:my_field);
  (:title, "My Fancy X");
  (:sort, "ascending");
  (:axis, {
    (:orient, "top");
    (:ticks, boolean_false);
    (:titleColor, "green");
    (:grid, boolean_false);
  })
}]

Outputs an x encoding with the :field set to "my_field". This chart would have a green x axis title of "My Fancy X" with the axis on the top of the chart. The axis would have no ticks and there would be no x gridlines on the chart. The data would be sorted in ascending order (other common options are "descending", "y" (sorts the x data by the y field in ascending order), or "-y" (sorts the x data by the y field in descending order)). See the Vega-Lite axis docs (opens in a new tab) for all of the :axis options.

x2

View source
x2[:field_name]
x2[value]
x2[CONFIG]

Set the encoding for the x2 position channel (opens in a new tab). If CONFIG is a unary RelName, the value is assumed to be a field name and is prepended with (:encoding, :x2, :field). If CONFIG is any other unary value, it is assumed to be a value and is prepended with (:encoding, :x2, :value). Any tuples with arity >= 2 are prepended with (:encoding, :x2).

The x2 position channel is most commonly used when specifying ranges of x values, such as in a gantt chart (opens in a new tab).

xError

View source
xError[:field_name]
xError[value]
xError[CONFIG]

Set the encoding for the xError position channel (opens in a new tab). If CONFIG is a unary RelName, the value is assumed to be a field name and is prepended with (:encoding, :xError, :field). If CONFIG is any other unary value, it is assumed to be a value and is prepended with (:encoding, :xError, :value). Any tuples with arity >= 2 are prepended with (:encoding, :xError).

The xError position channel is most commonly used when specifying error bar marks (opens in a new tab).

xError2

View source
xError2[:field_name]
xError2[value]
xError2[CONFIG]

Set the encoding for the xError2 position channel (opens in a new tab). If CONFIG is a unary RelName, the value is assumed to be a field name and is prepended with (:encoding, :xError2, :field). If CONFIG is any other unary value, it is assumed to be a value and is prepended with (:encoding, :xError2, :value). Any tuples with arity >= 2 are prepended with (:encoding, :xError2).

The xError2 position channel is most commonly used when specifying error bar marks (opens in a new tab).

xOffset

View source
xOffset[:field_name]
xOffset[value]
xOffset[CONFIG]

Set the encoding for the xOffset position offset channel (opens in a new tab). If CONFIG is a unary RelName, the value is assumed to be a field name and is prepended with (:encoding, :xOffset, :field). If CONFIG is any other unary value, it is assumed to be a value and is prepended with (:encoding, :xOffset, :value). Any tuples with arity >= 2 are prepended with (:encoding, :xOffset).

The xOffset position offset channel is most commonly used when creating a grouped bar chart or a jittered scatter plot.

y

View source
y[:field_name]
y[value]
y[CONFIG]

Set the encoding for the y position channel (opens in a new tab). If CONFIG is a unary RelName, the value is assumed to be a field name and is prepended with (:encoding, :y, :field). If CONFIG is any other unary value, it is assumed to be a value and is prepended with (:encoding, :y, :value). Any tuples with arity >= 2 are prepended with (:encoding, :y).

Examples

Set y to a field

def output = vegalite_utils:y[:my_field]

Outputs (:encoding, :y, :field, "my_field"). By default, the field name is then used as the axis title on the y axis.

Set y to a value

def output = vegalite_utils:y[202]

Outputs (:encoding, :y, :value, 200). This is less commonly used compared to defining y with a field, but can be useful when adding a horizontal line to a chart.

Set y to a field and set some options

def output = vegalite_utils:y[{
  (:my_field);
  (:title, "My Fancy Y");
  (:sort, "ascending");
  (:axis, {
    (:orient, "right");
    (:ticks, boolean_false);
    (:titleColor, "green");
    (:grid, boolean_false);
  })
}]

Outputs an y encoding with the :field set to "my_field". This chart would have a green y axis title of "My Fancy Y" with the axis on the right of the chart. The axis would have no ticks and there would be no x gridlines on the chart. The data would be sorted in ascending order (other common options are "descending", "x" (sorts the y data by the x field in ascending order), or "-x" (sorts the y data by the x field in descending order)). See the Vega-Lite axis docs (opens in a new tab) for all of the :axis options.

y2

View source
y2[:field_name]
y2[value]
y2[CONFIG]

Set the encoding for the y2 position channel (opens in a new tab). If CONFIG is a unary RelName, the value is assumed to be a field name and is prepended with (:encoding, :y2, :field). If CONFIG is any other unary value, it is assumed to be a value and is prepended with (:encoding, :y2, :value). Any tuples with arity >= 2 are prepended with (:encoding, :y2).

The y2 position channel is most commonly used when specifying ranges of y values, such as in a waterfall chart (opens in a new tab) ( this example is quite complex, but note the y2 is simply set to a field).

yError

View source
yError[:field_name]
yError[value]
yError[CONFIG]

Set the encoding for the yError position channel (opens in a new tab). If CONFIG is a unary RelName, the value is assumed to be a field name and is prepended with (:encoding, :yError, :field). If CONFIG is any other unary value, it is assumed to be a value and is prepended with (:encoding, :yError, :value). Any tuples with arity >= 2 are prepended with (:encoding, :yError).

The yError position channel is most commonly used when specifying error bar marks (opens in a new tab).

yError2

View source
yError2[:field_name]
yErro2[value]
yError2[CONFIG]

Set the encoding for the yError2 position channel (opens in a new tab). If CONFIG is a unary RelName, the value is assumed to be a field name and is prepended with (:encoding, :yError2, :field). If CONFIG is any other unary value, it is assumed to be a value and is prepended with (:encoding, :yError2, :value). Any tuples with arity >= 2 are prepended with (:encoding, :yError2).

The yError2 position channel is most commonly used when specifying error bar marks (opens in a new tab).

yOffset

View source
yOffset[:field_name]
yOffset[value]
yOffset[CONFIG]

Set the encoding for the yOffset position offset channel (opens in a new tab). If CONFIG is a unary RelName, the value is assumed to be a field name and is prepended with (:encoding, :yOffset, :field). If CONFIG is any other unary value, it is assumed to be a value and is prepended with (:encoding, :yOffset, :value). Any tuples with arity >= 2 are prepended with (:encoding, :yOffset).

The yOffset position offset channel is most commonly used when creating a grouped bar chart or a jittered scatter plot.

color

View source
color[:field_name]
color[value]
color[CONFIG]

Set the encoding for the color mark property channel (opens in a new tab). If CONFIG is a unary RelName, the value is assumed to be a field name and is prepended with (:encoding, :color, :field). If CONFIG is any other unary value, it is assumed to be a value and is prepended with (:encoding, :color, :value). Any tuples with arity >= 2 are prepended with (:encoding, :color).

Examples

Set color to a value

def output = vegalite_utils:color["cornflowerblue"]

Outputs (:encoding, :color, :value, "cornflowerblue"). Sets the color of the marks to Cornflower Blue (opens in a new tab).

Set color to a field

def output = vegalite_utils:color[:my_field]

Outputs (:encoding, :color, :field, "my_field"). When adding a color specification to a chart, it groups the data by that field. This results in multiple lines (opens in a new tab) with a :line mark, a stacked bar chart (opens in a new tab), or colored points on a scatter plot (opens in a new tab).

Set color to a predefined scheme, no legend

def output = vegalite_utils:color[{
  (:my_field);
  (:scale, :scheme, "dark2");
  (:legend, boolean_false)
}]

Outputs a color encoding with the :field set to "my_field". The "dark2" color scheme (opens in a new tab) is used instead of the default. The legend is suppressed by setting :legend to false.

Set color to a custom scheme, legend title

def output = vegalite_utils:color[{
  (:my_field);
  (:title, "Weather");
  (:scheme, {
    (:domain, :[], {(1, "sun"); (2, "fog"); (3, "rain")});
    (:range, :[], {(1, "yellow"); (2, "grey"); (3, "aqua")})
  })
}]

Outputs a color encoding with the :field set to "my_field". The legend title is set to "Weather" and the color scheme uses a custom mapping from data values in :my_field to colors (e.g. sun = yellow).

opacity

View source
opacity[:field_name]
opacity[value]
opacity[CONFIG]

Set the encoding for the opacity mark property channel (opens in a new tab). If CONFIG is a unary RelName, the value is assumed to be a field name and is prepended with (:encoding, :opacity, :field). If CONFIG is any other unary value, it is assumed to be a value and is prepended with (:encoding, :opacity, :value). Any tuples with arity >= 2 are prepended with (:encoding, :opacity).

Examples

Set opacity to a value

def output = vegalite_utils:opacity[0.7]

Outputs (:encoding, :opacity, :value, 0.7). Sets the opacity of the marks to 0.7. Setting the opacity to 1 makes the marks fully opaque (the default), whereas setting it to 0 makes the marks fully transparent.

Set opacity to a field

def output = vegalite_utils:opacity[:my_field]

Outputs (:encoding, :opacity, :field, "my_field"). When adding an opacity specification to a chart, it should be used with continuous quantitative data.

Change the opacity of a mark based on the value of the data

def output = vegalite_utils:opacity[{
  (0.9);
  (:condition, {
    (:test, "datum.my_field == 'A'");
    (:value, 0.5);
  })
}]

Outputs an opacity encoding with the :value set to 0.9. Then uses a condition to test if the data for the mark has my_field = 'A' and if so, sets the opacity to 0.5.

Change the opacity of a mark based on hover

def output = vegalite_utils:opacity[{
  :condition, {
    (:param, "hover");
    (:value, 0.5);
  };
}]

Uses a condition to test if the mark is being hovered over and if so, sets the opacity to 0.5. Otherwise, the default opacity of 1.0 is used.

fillOpacity

View source
fillOpacity[:field_name]
fillOpacity[value]
fillOpacity[CONFIG]

Set the encoding for the fillOpacity mark property channel (opens in a new tab). The fill opacity sets the opacity of only the interior of a mark (such as a circle). If CONFIG is a unary RelName, the value is assumed to be a field name and is prepended with (:encoding, :fillOpacity, :field). If CONFIG is any other unary value, it is assumed to be a value and is prepended with (:encoding, :fillOpacity, :value). Any tuples with arity >= 2 are prepended with (:encoding, :fillOpacity).

Examples

Set fill opacity to a value

def output = vegalite_utils:fillOpacity[0.7]

Outputs (:encoding, :fillOpacity, :value, 0.7). Sets the fill opacity of the marks to 0.7. Setting the fill opacity to 1 makes the marks fully opaque, whereas setting it to 0 makes the marks fully transparent.

Set fill opacity to a field

def output = vegalite_utils:fillOpacity[:my_field]

Outputs (:encoding, :fillOpacity, :field, "my_field"). When adding an opacity specification to a chart, it should be used with continuous quantitative data.

Change the fill opacity of a mark based on the value of the data

def output = vegalite_utils:fillOpacity[{
  (0.9);
  (:condition, {
    (:test, "datum.my_field == 'A'");
    (:value, 0.5);
  }}
}]

Outputs a fill opacity encoding with the :value set to 0.9. Then uses a condition to test if the data for the mark has my_field = 'A' and if so, sets the opacity to 0.5.

Change the fill opacity of a mark based on hover

def output = vegalite_utils:fillOpacity[{
  :condition, {
    (:param, "hover");
    (:value, 0.5);
  };
}]

Uses a condition to test if the mark is being hovered over and if so, sets the fill opacity to 0.5. Otherwise, the default opacity is used.

strokeOpacity

View source
strokeOpacity[:field_name]
strokeOpacity[value]
strokeOpacity[CONFIG]

Set the encoding for the strokeOpacity mark property channel (opens in a new tab). The stroke opacity sets the opacity of only the exterior of a mark (such as a circle) or a line. If CONFIG is a unary RelName, the value is assumed to be a field name and is prepended with (:encoding, :strokeOpacity, :field). If CONFIG is any other unary value, it is assumed to be a value and is prepended with (:encoding, :strokeOpacity, :value). Any tuples with arity >= 2 are prepended with (:encoding, :strokeOpacity).

Examples

Set stroke opacity to a value

def output = vegalite_utils:strokeOpacity[0.7]

Outputs (:encoding, :strokeOpacity, :value, 0.7). Sets the stroke opacity of the marks to 0.7. Setting the stroke opacity to 1 makes the marks fully opaque, whereas setting it to 0 makes the marks fully transparent.

Set stroke opacity to a field

def output = vegalite_utils:strokeOpacity[:my_field]

Outputs (:encoding, :strokeOpacity, :field, "my_field"). When adding an opacity specification to a chart, it should be used with continuous quantitative data.

Change the stroke opacity of a mark based on the value of the data

def output = vegalite_utils:strokeOpacity[{
  (0.9);
  (:condition, {
    (:test, "datum.my_field == 'A'");
    (:value, 0.5);
  })
}]

Outputs a stroke opacity encoding with the :value set to 0.9. Then uses a condition to test if the data for the mark has my_field = 'A' and if so, sets the opacity to 0.5.

Change the stroke opacity of a mark based on hover

def output = vegalite_utils:strokeOpacity[{
  :condition, {
    (:param, "hover");
    (:value, 0.5);
  };
}]

Uses a condition to test if the mark is being hovered over and if so, sets the stroke opacity to 0.5. Otherwise, the default opacity is used.

strokeWidth

View source
strokeWidth[:field_name]
strokeWidth[value]
strokeWidth[CONFIG]

Set the encoding for the strokeWidth mark property channel (opens in a new tab). The stroke width sets the width of a line or the outline of a mark (such as a circle). If CONFIG is a unary RelName, the value is assumed to be a field name and is prepended with (:encoding, :strokeWidth, :field). If CONFIG is any other unary value, it is assumed to be a value and is prepended with (:encoding, :strokeWidth, :value). Any tuples with arity >= 2 are prepended with (:encoding, :strokeWidth).

Examples

Set stroke width to a value

def output = vegalite_utils:strokeWidth[2]

Outputs (:encoding, :strokeWidth, :value, 2). Sets the stroke width of the marks to 2 pixels.

Set stroke width to a field

def output = vegalite_utils:strokeWidth[:my_field]

Outputs (:encoding, :strokeWidth, :field, "my_field").

Change the stroke width of a mark based on the value of the data

def output = vegalite_utils:strokeWidth[{
  (2);
  (:condition, {
    (:test, "datum.my_field == 'A'");
    (:value, 4);
  });
}]

Outputs a stroke width encoding with the :value set to 2. Then uses a condition to test if the data for the mark has my_field = 'A' and if so, sets the width to 4 pixels.

Change the stroke width of a mark based on hover

def output = vegalite_utils:strokeWidth[{
  :condition, {
    (:param, "hover");
    (:value, 4);
  };
}]

Uses a condition to test if the mark is being hovered over and if so, sets the stroke width to 4 pixels. Otherwise, the default width is used.

strokeDash

View source
strokeDash[:field_name]
strokeDash[value]
strokeDash[CONFIG]

Set the encoding for the strokeDash mark property channel (opens in a new tab). The stroke dash sets the pattern of a line or the outline of a mark (such as a circle). If CONFIG is a unary RelName, the value is assumed to be a field name and is prepended with (:encoding, :strokeDash, :field). If CONFIG is any other unary value, it is assumed to be a value and is prepended with (:encoding, :strokeDash, :value). Any tuples with arity >= 2 are prepended with (:encoding, :strokeDash).

Examples

Set stroke dash to a field

def output = vegalite_utils:strokeDash[:my_field]

Outputs (:encoding, :strokeDash, :field, "my_field"). When adding a stroke dash specification to a chart, it groups the data by that field. This results in multiple lines with a :line mark.

Set stroke dash to a field with custom title

def output = vegalite_utils:strokeDash[{
  (:my_field);
  (:title, "My Field")
}]

Outputs (:encoding, :strokeDash, :field, "my_field"). When adding a stroke dash specification to a chart, it groups the data by that field. This results in multiple lines with a :line mark. Setting the :title updates the title on the legend (included by default), and the tooltip.

size

View source
size[:field_name]
size[value]
size[CONFIG]

Set the encoding for the size mark property channel (opens in a new tab). If CONFIG is a unary RelName, the value is assumed to be a field name and is prepended with (:encoding, :size, :field). If CONFIG is any other unary value, it is assumed to be a value and is prepended with (:encoding, :size, :value). Any tuples with arity >= 2 are prepended with (:encoding, :size).

Adding size to a scatter chart, converts it to a bubble plot (opens in a new tab).

Examples

Set size to a value

def output = vegalite_utils:size[20]

Outputs (:encoding, :size, :field, "my_field"). The size property is most commonly used with "point", "square", and "circle" marks where the value of 20 is then the area of the mark.

Set size to a field

def output = vegalite_utils:size[:my_field]

Outputs (:encoding, :size, :field, "my_field").

Set size to a field with custom title

def output = vegalite_utils:size[{
  (:my_field);
  (:title, "My Field")
}]

Outputs (:encoding, :size, :field, "my_field"). Setting the :title updates the title on the legend (included by default), and the tooltip.

Create a bubble plot

def data:height = {(1, 102); (2, 94); (3, 74)}
def data:wingspan = {(1, 36.2); (2, 45.2); (3, 35.0)}
def data:weight = {(1, 20.1); (2, 15.4); (3, 20.4) }
 
def chart = vegalite:scatter[:height, :wingspan, { :data, data; :size, :weight }]
 
def output = vegalite:plot[chart]

Outputs a bubble plot with height on the x axis, wingspan on the y axis, and the points sized by weight.

angle

View source
angle[:field_name]
angle[value]
angle[CONFIG]

Set the encoding for the angle mark property channel (opens in a new tab). The angle property sets the angle of text or point marks (e.g. rotating a text mark to 45 degrees). If CONFIG is a unary RelName, the value is assumed to be a field name and is prepended with (:encoding, :angle, :field). If CONFIG is any other unary value, it is assumed to be a value and is prepended with (:encoding, :angle, :value). Any tuples with arity >= 2 are prepended with (:encoding, :angle).

Examples

Set angle to a value

rel``` def output = vegalite_utils:angle[45]

Outputs `(:encoding, :angle, :value, 45)`. This rotates the angle of the mark 45 degrees
clockwise.

<p className="docstring-level-3">Set angle to a field</p>
rel```
def output = vegalite_utils:angle[:direction]

Outputs (:encoding, :angle, :field, "direction"). This rotates the angle of each mark by the value in the field :direction.

shape

View source
shape[:field_name]
shape[value]
shape[CONFIG]

Set the encoding for the shape mark property channel (opens in a new tab). The shape property is used primarily with "point" marks. If CONFIG is a unary RelName, the value is assumed to be a field name and is prepended with (:encoding, :shape, :field). If CONFIG is any other unary value, it is assumed to be a value and is prepended with (:encoding, :shape, :value). Any tuples with arity >= 2 are prepended with (:encoding, :shape).

Examples

Set shape to a value

def output = vegalite_utils:shape["square"]

Outputs (:encoding, :shape, :value, "square"). Possible values:

  • "circle"
  • "cross"
  • "diamond"
  • "square"
  • "triangle-up"
  • "triangle-down"
  • "triangle-left"
  • "triangle-right"
  • "stroke"
  • "wedge"
  • "arrow"
  • "triangle"
  • An SVG path string

Set size to a field

def output = vegalite_utils:shape[:my_field]

Outputs (:encoding, :shape, :field, "my_field").

Set shape to a field with custom title

def output = vegalite_utils:shape[{
  (:my_field);
  (:title, "My Field")
}]

Outputs (:encoding, :shape, :field, "my_field"). Setting the :title updates the title on the legend (included by default), and the tooltip.

theta

View source
theta[:field_name]
theta[value]
theta[CONFIG]

Set the encoding for the theta polar position channel (opens in a new tab). The theta property is used with "arc" marks. If CONFIG is a unary RelName, the value is assumed to be a field name and is prepended with (:encoding, :theta, :field). If CONFIG is any other unary value, it is assumed to be a value and is prepended with (:encoding, :theta, :value). Any tuples with arity >= 2 are prepended with (:encoding, :theta).

Examples

Set theta to a field

def output = vegalite_utils:theta[:my_field]

Outputs (:encoding, :theta, :field, "my_field"). This sets the size of the arcs based on the data in my field so that the arcs create a circle.

Create a pie chart

def data:count = {(1, 20); (2, 40) }
def data:response = {(1, "No"); (2, "Yes")}
 
def chart = vegalite_utils:data[data]
def chart = vegalite_utils:theta[{(:count); (:type, "quantitative")}]
def chart = vegalite_utils:color[{(:response); (:type, "nominal")}]
def chart = {:mark, "arc"}
 
def output = vegalite:plot[chart]

Output a pie chart with two wedges, "No" and "Yes", which are sized to 1/3 and 2/3 of the circle respectively.

theta2

View source
theta2[:field_name]
theta2[value]
theta2[CONFIG]

Set the encoding for the theta2 polar position channel (opens in a new tab). The theta2 property is used with "arc" marks. If CONFIG is a unary RelName, the value is assumed to be a field name and is prepended with (:encoding, :theta2, :field). If CONFIG is any other unary value, it is assumed to be a value and is prepended with (:encoding, :theta2, :value). Any tuples with arity >= 2 are prepended with (:encoding, :theta2).

Examples

Set theta2 to a field

def output = vegalite_utils:theta2[:my_field]

Outputs (:encoding, :theta2, :field, "my_field"). This sets the end angle of the arc in radians, to the values in :my_field.

radius

View source
radius[:field_name]
radius[value]
radius[CONFIG]

Set the encoding for the radius polar position channel (opens in a new tab). The radius property is used with "arc" marks. If CONFIG is a unary RelName, the value is assumed to be a field name and is prepended with (:encoding, :radius, :field). If CONFIG is any other unary value, it is assumed to be a value and is prepended with (:encoding, :radius, :value). Any tuples with arity >= 2 are prepended with (:encoding, :radius).

Examples

Set radius to a value

def output = vegalite_utils:radius[240]

Outputs (:encoding, :radius, :value, 240). This sets the outer radius of the arc marks to 240 pixels.

radius2

View source
radius2[:field_name]
radius2[value]
radius2[CONFIG]

Set the encoding for the radius2 polar position channel (opens in a new tab). The radius2 property is used with "arc" marks. If CONFIG is a unary RelName, the value is assumed to be a field name and is prepended with (:encoding, :radius2, :field). If CONFIG is any other unary value, it is assumed to be a value and is prepended with (:encoding, :radius2, :value). Any tuples with arity >= 2 are prepended with (:encoding, :radius2).

Examples

Set radius to a value

def output = vegalite_utils:radius2[120]

Outputs (:encoding, :radius2, :value, 120). This sets the inner radius of the arc marks to 120 pixels.

longitude

View source
longitude[:field_name]
longitude[value]
longitude[CONFIG]

Set the encoding for the longitude geographic position channel (opens in a new tab). The longitude property is typically used along with a projection (opens in a new tab). If CONFIG is a unary RelName, the value is assumed to be a field name and is prepended with (:encoding, :longitude, :field). If CONFIG is any other unary value, it is assumed to be a value and is prepended with (:encoding, :longitude, :value). Any tuples with arity >= 2 are prepended with (:encoding, :longitude).

Examples

Set longitude to a field

def output = vegalite_utils:longitude[:lons]

Outputs (:encoding, :longitude, :field, "lons"). This sets the longitude position of geographically project marks to the field :lons. See the Vega-Lite Maps examples (opens in a new tab) for use cases on using longitude.

longitude2

View source
longitude2[:field_name]
longitude2[value]
longitude2[CONFIG]

Set the encoding for the longitude2 geographic position channel (opens in a new tab). The longitude2 property is typically used along with a projection (opens in a new tab). If CONFIG is a unary RelName, the value is assumed to be a field name and is prepended with (:encoding, :longitude2, :field). If CONFIG is any other unary value, it is assumed to be a value and is prepended with (:encoding, :longitude2, :value). Any tuples with arity >= 2 are prepended with (:encoding, :longitude2).

Examples

Set longitude2 to a field

def output = vegalite_utils:longitude2[:lons]

Outputs (:encoding, :longitude2, :field, "lons"). This sets the longitude2 position of geographically project marks to the field :lons. See the Vega-Lite Maps examples (opens in a new tab) for use cases on using longitude2.

latitude

View source
latitude[:field_name]
latitude[value]
latitude[CONFIG]

Set the encoding for the latitude geographic position channel (opens in a new tab). The latitude property is typically used along with a projection (opens in a new tab). If CONFIG is a unary RelName, the value is assumed to be a field name and is prepended with (:encoding, :latitude, :field). If CONFIG is any other unary value, it is assumed to be a value and is prepended with (:encoding, :latitude, :value). Any tuples with arity >= 2 are prepended with (:encoding, :latitude).

Examples

Set latitude to a field

def output = vegalite_utils:latitude[:lats]

Outputs (:encoding, :latitude, :field, "lats"). This sets the latitude position of geographically project marks to the field :lats. See the Vega-Lite Maps examples (opens in a new tab) for use cases on using latitude.

latitude2

View source
latitude2[:field_name]
latitude2[value]
latitude2[CONFIG]

Set the encoding for the latitude2 geographic position channel (opens in a new tab). The latitude2 property is typically used along with a projection (opens in a new tab). If CONFIG is a unary RelName, the value is assumed to be a field name and is prepended with (:encoding, :latitude2, :field). If CONFIG is any other unary value, it is assumed to be a value and is prepended with (:encoding, :latitude2, :value). Any tuples with arity >= 2 are prepended with (:encoding, :latitude2).

Examples

Set latitude2 to a field

def output = vegalite_utils:latitude2[:lats]

Outputs (:encoding, :latitude2, :field, "lats"). This sets the latitude position of geographically project marks to the field :lats. See the Vega-Lite Maps examples (opens in a new tab) for use cases on using latitude2.

text

View source
text[:field_name]
text[value]
text[CONFIG]

Set the encoding for the text channel (opens in a new tab). Used with the "text" mark type. If CONFIG is a unary RelName, the value is assumed to be a field name and is prepended with (:encoding, :text, :field). If CONFIG is any other unary value, it is assumed to be a value and is prepended with (:encoding, :text, :value). Any tuples with arity >= 2 are prepended with (:encoding, :text).

Examples

Set text to a field

def output = vegalite_utils:text[:words]

Outputs (:encoding, :text, :field, "words"). This sets the marks to the text contained in the field :words.

tooltip

View source
tooltip[:field_name]
tooltip[value]
tooltip[CONFIG]

Set the encoding for the tooltip channel (opens in a new tab). The tooltip text to show upon mouse hover. By default, the tooltip will contain key/value pairs with the data at the hovered point. This channel can be used to override that behavior. See the tooltip documentation (opens in a new tab) for more details. If CONFIG is a unary RelName, the value is assumed to be a field name and is prepended with (:encoding, :tooltip, :field). If CONFIG is any other unary value, it is assumed to be a value and is prepended with (:encoding, :tooltip, :value). Any tuples with arity >= 2 are prepended with (:encoding, :tooltip).

href

View source
href[:field_name]
href[value]
href[CONFIG]

Set the encoding for the href hyperlink channel (opens in a new tab). Setting the "href" property turns a mark into a hyperlink. If CONFIG is a unary RelName, the value is assumed to be a field name and is prepended with (:encoding, :href, :field). If CONFIG is any other unary value, it is assumed to be a value and is prepended with (:encoding, :href, :value). Any tuples with arity >= 2 are prepended with (:encoding, :href).

Examples

Set href to a field

def output = vegalite_utils:href[:links]

Outputs (:encoding, :href, :field, "links"). This sets the marks to be hyperlinks pointing to the links contained in the field :links.

detail

View source
detail[:field_name]
detail[value]
detail[CONFIG]

Set the encoding for the level of detail channel (opens in a new tab). Setting the "detail" property adds a grouping to the plot without mapping the marks to visual properties (e.g. multiple lines all of the same color). If CONFIG is a unary RelName, the value is assumed to be a field name and is prepended with (:encoding, :detail, :field). If CONFIG is any other unary value, it is assumed to be a value and is prepended with (:encoding, :detail, :value). Any tuples with arity >= 2 are prepended with (:encoding, :detail).

Examples

Set detail to a field

def output = vegalite_utils:detail[:category]

Outputs (:encoding, :detail, :field, "category"). This adds a mark grouping to categories contained in the field :category.

key

View source
key[:field_name]
key[value]
key[CONFIG]

Set the encoding for the key channel (opens in a new tab). Setting the "key" property adds a key to the data for consistency when programmatically changing data via the API. If CONFIG is a unary RelName, the value is assumed to be a field name and is prepended with (:encoding, :key, :field). If CONFIG is any other unary value, it is assumed to be a value and is prepended with (:encoding, :key, :value). Any tuples with arity >= 2 are prepended with (:encoding, :key).

order

View source
order[:field_name]
order[value]
order[CONFIG]

Set the encoding for the order channel (opens in a new tab). Setting the "order" property sets the stacking order for stacked charts (see vegalite_utils:sort for setting the order of non-stacked marks). If CONFIG is a unary RelName, the value is assumed to be a field name and is prepended with (:encoding, :order, :field). If CONFIG is any other unary value, it is assumed to be a value and is prepended with (:encoding, :order, :value). Any tuples with arity >= 2 are prepended with (:encoding, :order).

facet

View source
facet[:field_name]
facet[value]
facet[CONFIG]

Set the encoding for the facet channel (opens in a new tab). Setting the "facet" property creates subplots by the field specified. If CONFIG is a unary RelName, the value is assumed to be a field name and is prepended with (:encoding, :facet, :field). If CONFIG is any other unary value, it is assumed to be a value and is prepended with (:encoding, :facet, :value). Any tuples with arity >= 2 are prepended with (:encoding, :facet).

Examples

Set facet to a field

def output = vegalite_utils:facet[:my_field]

Outputs (:encoding, :facet, :field, "my_field"). This creates a row of subplots, where the data is divided by the values of :my_field.

Create a wrapped, ordered facet

def output = vegalite_utils:facet[{
  (:my_field);
  (:columns, 2);
  (:sort, {(:op, "median"); (:field, "other_field")})
}]

Outputs (:encoding, :facet, :field, "my_field"). This creates two columns of subplots, where the data is divided by the values of :my_field. The order of the subplots is determined by the median value of :other_field.

row

View source
row[:field_name]
row[value]
row[CONFIG]

Set the encoding for the row channel (opens in a new tab). Setting the "row" property creates a column of subplots where is row is determined by the field specified. If CONFIG is a unary RelName, the value is assumed to be a field name and is prepended with(:encoding, :row, :field). If CONFIG is any other unary value, it is assumed to be a value and is prepended with (:encoding, :row, :value). Any tuples with arity >= 2 are prepended with (:encoding, :row).

Examples

Set row to a field

def output = vegalite_utils:row[:my_field]

Outputs (:encoding, :row, :field, "my_field"). This creates a column of subplots, where the data is divided by the values of :my_field.

Create a grid of subplots

def output = vegalite_utils:row[:my_field]
def output = vegalite_utils:column[:other_field]

Outputs (:encoding, :row, :field, "my_field") and (:encoding, :column, :field, "other_field"). This creates a grid of subplots, where for each row the data is divided by the values of :my_field and for each column the data is divided by :other_field.

column

View source
column[:field_name]
column[value]
column[CONFIG]

Set the encoding for the column channel (opens in a new tab). Setting the "column" property creates a column of subplots where is row is determined by the field specified. If CONFIG is a unary RelName, the value is assumed to be a field name and is prepended with(:encoding, :column, :field). If CONFIG is any other unary value, it is assumed to be a value and is prepended with (:encoding, :column, :value). Any tuples with arity >= 2 are prepended with (:encoding, :column).

Examples

Set column to a field

def output = vegalite_utils:column[:my_field]

Outputs (:encoding, :column, :field, "my_field"). This creates a row of subplots, where the data is divided by the values of :my_field.

Create a grid of subplots

def output = vegalite_utils:column[:my_field]
def output = vegalite_utils:row[:other_field]

Outputs (:encoding, :column, :field, "my_field") and (:encoding, :row, :field, "other_field"). This creates a grid of subplots, where for each column the data is divided by the values of :my_field and for each row the data is divided by :other_field.

Was this doc helpful?