The Vega-Lite Visualization Library (vega-lite)
Vega-Lite Visualization Library
Module: vegalite
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 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 anX
relation specifying thex
field (categorical data), aY
relation specifying they
field (quantitative data), and aCONFIG
relation (see the section onCONFIG
below), gives a relation specifying a bar chart in vegalite.scatter[X, Y, CONFIG]
: Given anX
relation specifying thex
field (quantitative data), aY
relation specifying they
field (quantitative data), and aCONFIG
relation (see the section onCONFIG
below), gives a relation specifying a scatter chart in vegalite.line[X, Y, CONFIG]
: Given anX
relation specifying thex
field (quantitative data), aY
relation specifying they
field (quantitative data), and aCONFIG
relation (see the section onCONFIG
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 sort[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
// from the "Machine Learning (Classification)" How-To guide
def file_config[:path] = "s3://relationalai-documentation-public/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 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:
- Creating the stacking of the bar chart by coloring each bar by the
:sex
breakdown within each:species
, grouping the chart data by:sex
. - 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 thevegalite_templates:bar
relation). - The color scheme is being changed from the default (
"tableau10"
) to the"dark2"
scheme. See the Vega documentation 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.
See Also:
vega
vegalite_utils
vegalite_templates
right_override
load_csv
parse_json
bar
bar[X, Y, CONFIG]
Construct a Vega-Lite specification for a bar chart.
Arguments
X
: A relation specifying thex
field in the chart. Typically, aRelName
(e.g.:category
) will be passed to indicate the field in the:data
to use as thex
data. By default, this is set to “nominal” 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.Y
: A relation specifying they
field in the chart. Typically, aRelName
(e.g.:amount
) will be passed to indicate the field in the:data
to use as they
data. An:aggregate
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” data. Can accept any values accepted by the:y
encoding channel.CONFIG
: An overloaded relation with configuration for the chart. At a minimum, must contain the(:data, DATA)
tuple, whereDATA
is a relation in the column-wise format(field, keys..., value)
. Any tuple in theCONFIG
relation can contain the name of a utility fromvegalite_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
// from the "Machine Learning (Classification)" How-To guide
def file_config[:path] = "s3://relationalai-documentation-public/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 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:
- creating the stacking of the bar chart by coloring each bar by the
:sex
breakdown within each:species
. - 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 thevegalite_templates:bar
relation). - The color scheme is being changed from the default (
"tableau10"
) to the"dark2"
scheme. See the vega documentation 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.
Definition
def bar[X, Y, CONFIG] = {
vegalite_utils:x[X];
vegalite_utils:y[Y];
(vegalite_utils[util, CONFIG[util]] from util);
} <++ vegalite_templates:bar
line
line[X, Y, CONFIG]
Construct a Vega-Lite specification for a line chart.
Arguments
X
: A relation specifying thex
field in the chart. Typically, aRelName
(e.g.:year
) will be passed to indicate the field in the:data
to use as thex
data. By default, this is set to “quantitative” data (i.e. categorical). Can accept any values accepted by the:x
encoding channel.Y
: A relation specifying they
field in the chart. Typically, aRelName
(e.g.:price
) will be passed to indicate the field in the:data
to use as they
data. An:aggregate
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” data. Can accept any values accepted by the:y
encoding channel.CONFIG
: An overloaded relation with configuration for the chart. At a minimum, must contain the(:data, DATA)
tuple, whereDATA
is a relation in the column-wise format(field, keys..., value)
. Any tuple in theCONFIG
relation can contain the name of a utility fromvegalite_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
// from the "Machine Learning (Regression)" How-To guide
def file_config[:path] = "s3://relationalai-documentation-public/ml-regression/airfoil/airfoil_self_noise.dat"
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] = ' '
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[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.
Definition
def line[X, Y, CONFIG] = {
vegalite_utils:x[X];
vegalite_utils:y[Y];
(vegalite_utils[util, CONFIG[util]] from util);
} <++ vegalite_templates:line
plot
plot[R]
Combine the Vega-Lite schema relation R
with the Vega-Lite MIME type to be richly rendered
by the client.
Definition
def plot[R] = {
:MIME, MIME_REL_VEGALITE;
// This logic makes no assumptions on the valid json-structure of the relation R;
// instead that is checked in the front-end display.
:plot, :vegalite, R
}
scatter
scatter[X, Y, CONFIG]
Construct a Vega-Lite specification for a scatter plot.
Arguments
X
: A relation specifying thex
field in the chart. Typically, aRelName
(e.g.:height
) will be passed to indicate the field in the:data
to use as thex
data. By default, this is set to “quantitative” data (i.e. categorical). Can accept any values accepted by the:x
encoding channel.Y
: A relation specifying they
field in the chart. Typically, aRelName
(e.g.:wingspan
) will be passed to indicate the field in the:data
to use as they
data. An:aggregate
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” data. Can accept any values accepted by the:y
encoding channel.CONFIG
: An overloaded relation with configuration for the chart. At a minimum, must contain the(:data, DATA)
tuple, whereDATA
is a relation in the column-wise format(field, keys..., value)
. Any tuple in theCONFIG
relation can contain the name of a utility fromvegalite_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.
// from the "Machine Learning (Classification)" How-To guide
def file_config[:path] = "s3://relationalai-documentation-public/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[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.
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.
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).
Definition
def scatter[X, Y, CONFIG] = {
vegalite_utils:x[X];
vegalite_utils:y[Y];
(vegalite_utils[util, CONFIG[util]] from util);
} <++ vegalite_templates:scatter
Module: vegalite_templates
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 yscatter
: A scatter plot with quantitative data on both axesline
: A line chart with quantitative date on both axes
bar
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.
Definition
def bar = {
:mark, {:type, "bar"; :tooltip, boolean_true};
:encoding, :y, :type, "quantitative";
:encoding, :x, :type, "nominal";
}
line
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.
Definition
def line = {
:mark, {:type, "line"; :tooltip, boolean_true};
:encoding, :y, :type, "quantitative";
:encoding, :x, :type, "quantitative";
}
scatter
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.
Definition
def scatter = {
:mark, {:type, "point"; :tooltip, boolean_true};
:encoding, :y, :type, "quantitative";
:encoding, :x, :type, "quantitative";
}
Module: vegalite_utils
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.
angle
angle[:field_name]
angle[value]
angle[CONFIG]
Set the encoding for the angle mark property channel.
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.
**Set angle to a field**
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
.
Definition
def angle[CONFIG] = encoding[:angle, CONFIG]
background
background[c]
Set the background color of
the entire Vega-Lite chart to c
. Gives c
prepended with the :background
key.
Definition
def background[c] = {:background, c}
color
color[:field_name]
color[value]
color[CONFIG]
Set the encoding for the color mark property channel.
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.
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 with a :line
mark, a
stacked bar chart,
or colored points on a scatter plot.
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 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).
Definition
def color[CONFIG] = encoding[:color, CONFIG]
column
column[:field_name]
column[value]
column[CONFIG]
Set the encoding for the column channel.
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
.
Definition
def column[CONFIG] = encoding[:column, CONFIG]
data
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 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.
Definition
def data[DATA] = {
:data, :values, :[], i, field, value
from field, i, value
where sort[{ks2... : DATA[_](ks2...,_)}](i, ks...) and DATA(field, ks..., value)
from ks...
}
detail
detail[:field_name]
detail[value]
detail[CONFIG]
Set the encoding for the level of detail channel.
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
.
Definition
def detail[CONFIG] = encoding[:detail, CONFIG]
facet
facet[:field_name]
facet[value]
facet[CONFIG]
Set the encoding for the facet channel.
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
.
Definition
def facet[CONFIG] = encoding[:facet, CONFIG]
fillOpacity
fillOpacity[:field_name]
fillOpacity[value]
fillOpacity[CONFIG]
Set the encoding for the fillOpacity mark property channel.
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.
Definition
def fillOpacity[CONFIG] = encoding[:fillOpacity, CONFIG]
height
height[h]
Set the height
of the Vega-Lite chart in pixels. Gives h
prepended with the :height
key.
Definition
def height[h] = {:height, h}
href
href[:field_name]
href[value]
href[CONFIG]
Set the encoding for the href hyperlink channel.
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
.
Definition
def href[CONFIG] = encoding[:href, CONFIG]
key
key[:field_name]
key[value]
key[CONFIG]
Set the encoding for the key channel.
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)
.
Definition
def key[CONFIG] = encoding[:key, CONFIG]
latitude
latitude[:field_name]
latitude[value]
latitude[CONFIG]
Set the encoding for the latitude geographic position channel.
The latitude property is typically used along with a projection.
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
for use cases on using latitude.
Definition
def latitude[CONFIG] = encoding[:latitude, CONFIG]
latitude2
latitude2[:field_name]
latitude2[value]
latitude2[CONFIG]
Set the encoding for the latitude2 geographic position channel.
The latitude2 property is typically used along with a projection.
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
for use cases on using latitude2.
Definition
def latitude2[CONFIG] = encoding[:latitude2, CONFIG]
longitude
longitude[:field_name]
longitude[value]
longitude[CONFIG]
Set the encoding for the longitude geographic position channel.
The longitude property is typically used along with a projection.
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
for use cases on using longitude.
Definition
def longitude[CONFIG] = encoding[:longitude, CONFIG]
longitude2
longitude2[:field_name]
longitude2[value]
longitude2[CONFIG]
Set the encoding for the longitude2 geographic position channel.
The longitude2 property is typically used along with a projection.
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
for use cases on using longitude2.
Definition
def longitude2[CONFIG] = encoding[:longitude2, CONFIG]
opacity
opacity[:field_name]
opacity[value]
opacity[CONFIG]
Set the encoding for the opacity mark property channel.
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.
Definition
def opacity[CONFIG] = encoding[:opacity, CONFIG]
order
order[:field_name]
order[value]
order[CONFIG]
Set the encoding for the order channel.
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)
.
Definition
def order[CONFIG] = encoding[:order, CONFIG]
radius
radius[:field_name]
radius[value]
radius[CONFIG]
Set the encoding for the radius polar position channel.
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.
Definition
def radius[CONFIG] = encoding[:radius, CONFIG]
radius2
radius2[:field_name]
radius2[value]
radius2[CONFIG]
Set the encoding for the radius2 polar position channel.
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.
Definition
def radius2[CONFIG] = encoding[:radius2, CONFIG]
row
row[:field_name]
row[value]
row[CONFIG]
Set the encoding for the row channel.
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
.
Definition
def row[CONFIG] = encoding[:row, CONFIG]
shape
shape[:field_name]
shape[value]
shape[CONFIG]
Set the encoding for the shape mark property channel.
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.
Definition
def shape[CONFIG] = encoding[:shape, CONFIG]
size
size[:field_name]
size[value]
size[CONFIG]
Set the encoding for the size mark property channel.
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.
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.
Definition
def size[CONFIG] = encoding[:size, CONFIG]
strokeDash
strokeDash[:field_name]
strokeDash[value]
strokeDash[CONFIG]
Set the encoding for the strokeDash mark property channel.
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.
Definition
def strokeDash[CONFIG] = encoding[:strokeDash, CONFIG]
strokeOpacity
strokeOpacity[:field_name]
strokeOpacity[value]
strokeOpacity[CONFIG]
Set the encoding for the strokeOpacity mark property channel.
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.
Definition
def strokeOpacity[CONFIG] = encoding[:strokeOpacity, CONFIG]
strokeWidth
strokeWidth[:field_name]
strokeWidth[value]
strokeWidth[CONFIG]
Set the encoding for the strokeWidth mark property channel.
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.
Definition
def strokeWidth[CONFIG] = encoding[:strokeWidth, CONFIG]
text
text[:field_name]
text[value]
text[CONFIG]
Set the encoding for the text channel.
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
.
Definition
def text[CONFIG] = encoding[:text, CONFIG]
theta
theta[:field_name]
theta[value]
theta[CONFIG]
Set the encoding for the theta polar position channel.
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.
Definition
def theta[CONFIG] = encoding[:theta, CONFIG]
theta2
theta2[:field_name]
theta2[value]
theta2[CONFIG]
Set the encoding for the theta2 polar position channel.
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
.
Definition
def theta2[CONFIG] = encoding[:theta2, CONFIG]
title
title[t]
title[CONFIG]
Add the string t
as a title for the
Vega-Lite chart. Or provide an overloaded relation CONFIG
with keys and values as described
in the Vega-Lite docs (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.
Definition
def title[S] = {:title, :text, s} from s where S(s) and String(s)
def title[S] = {:title, k, v} from k, v where S(k, v)
tooltip
tooltip[:field_name]
tooltip[value]
tooltip[CONFIG]
Set the encoding for the tooltip channel.
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
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)
.
Definition
def tooltip[CONFIG] = encoding[:tooltip, CONFIG]
width
width[w]
Set the width
of the Vega-Lite chart in pixels. Gives w
prepended with the :width
key.
Definition
def width[w] = {:width, w}
x
x[:field_name]
x[value]
x[CONFIG]
Set the encoding for the x position channel.
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
for all of the :axis
options.
Definition
def x[CONFIG] = encoding[:x, CONFIG]
x2
x2[:field_name]
x2[value]
x2[CONFIG]
Set the encoding for the x2 position channel.
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.
Definition
def x2[CONFIG] = encoding[:x2, CONFIG]
xError
xError[:field_name]
xError[value]
xError[CONFIG]
Set the encoding for the xError position channel.
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.
Definition
def xError[CONFIG] = encoding[:xError, CONFIG]
xError2
xError2[:field_name]
xError2[value]
xError2[CONFIG]
Set the encoding for the xError2 position channel.
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.
Definition
def xError2[CONFIG] = encoding[:xError2, CONFIG]
xOffset
xOffset[:field_name]
xOffset[value]
xOffset[CONFIG]
Set the encoding for the xOffset position offset channel.
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.
Definition
def xOffset[CONFIG] = encoding[:xOffset, CONFIG]
y
y[:field_name]
y[value]
y[CONFIG]
Set the encoding for the y position channel.
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
for all of the :axis
options.
Definition
def y[CONFIG] = encoding[:y, CONFIG]
y2
y2[:field_name]
y2[value]
y2[CONFIG]
Set the encoding for the y2 position channel.
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 (
this example is quite complex, but note the y2
is simply set to a field).
Definition
def y2[CONFIG] = encoding[:y2, CONFIG]
yError
yError[:field_name]
yError[value]
yError[CONFIG]
Set the encoding for the yError position channel. 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.
Definition
def yError[CONFIG] = encoding[:yError, CONFIG]
yError2
yError2[:field_name]
yErro2[value]
yError2[CONFIG]
Set the encoding for the yError2 position channel.
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.
Definition
def yError2[CONFIG] = encoding[:yError2, CONFIG]
yOffset
yOffset[:field_name]
yOffset[value]
yOffset[CONFIG]
Set the encoding for the yOffset position offset channel.
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.
Definition
def yOffset[CONFIG] = encoding[:yOffset, CONFIG]