Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
This wiki documents Vega version 2. For Vega 3 documentation, see vega.github.io/vega.
Group marks are a special kind of mark that can contain other marks. A group mark definition is in many ways similar to the top-level Visualization definition: a group can contain scales, axes, legends and marks. However, note that one can not set top-level
data definitions. Instead, group marks use the same
"from" data definition and visual property sets as other marks.
Group marks can be used in a variety of designs. For example:
- To incorporate multiple visualizations within the same Vega specification.
- To create layered or stacked visualizations, in which each layer or stack contains a different subset of data.
- To create small multiples displays in which a visualization design is systematically repeated over different data subsets.
Group marks support the same visual properties as
rect marks. For instance, group marks can have
height values, as well as fill and stroke properties (
strokeDashOffset). By default, group marks have no stroke or fill, and inherit the spatial properties of their parent group or top-level visualization.
Group marks also support the following additional properties:
|clip||ValueRef → Boolean||If true, and the group's
Group marks are populated from data just like any other mark: the
from property defines a source data set along with any desired data transforms. One group instance will be created for each element in the backing data set. If no
from property is specified, the group will receive data from its parent group (if it is nested within another group) or will be backed by a single null value (if it is a top-level group).
Groups differ from other mark types in their ability to contain children marks. Marks defined within a group mark can inherit data from their parent group. For inheritance to work each data element for a group must contain data elements of its own. This arrangement of nested data is typically achieved by facetting the data, such that each group-level data element includes its own array of sub-elements. Facets can be constructed using the facet or window data transforms (see the Data Transforms page) or can be loaded directly as hierarchical data (e.g., using the treejson data type, see the Data page for more).
Scales, Axes and Legends
- Scales, axes and legends defined at the group level reference the width and height values of the current group, not the top-level visualization.
- If a scale is defined using the same name as a previously defined scale, the pre-existing scale will be shadowed (overloaded) by the new definition within the context of this group. Scale definitions cascade, so that any (non-shadowed) scales defined at a higher level are still accessible.
- Scale domain definitions can omit the (normally required)
"data"property. If no
"data"property is provided in the domain definition, the group-level data will be used to determine the domain. Note that this group-level data is exactly the same data that gets passed along to child marks.
Groups are perhaps more easily understood by example. The visualization specifications included with the online Vega editor showcase a number of use cases for groups, including:
- The stacked_area and jobs examples use a facet transform to gather data into individual series (or stacks). A group mark is then used to layer each stack. In this case, each group has the same position.
- The barley example similarly uses facets and group marks, but rather than layering data, each sub-group is placed in its own plot to create a small multiples display. In addition, a group-level scale is used to conveniently place items along the y-axis in each plot.
- The grouped_bar example uses the group mark to subdivide data to create a grouped bar chart display.
- The scatter_matrix example uses the cross transform and group marks to create a scatter plot matrix display.