This website is for Vega-Lite v3. Go to the main Vega-Lite homepage for the latest release.

Repeat a View

Edit this page

The repeat operator is part of Vega-Lite’s view composition. It provides a shortcut that creates a view for each entry in an array of fields. This operator generates multiple plots like facet. However, unlike facet it allows full replication of a data set in each view.

Documentation Overview

Repeat Operator

To repeat a view, define what fields should be used for each entry. Then define the repeated view in spec with a reference to a repeated field ({"repeat": ...}).

{
  "repeat": {
    ... // Repeat definition
  },
  "spec": ... // Specification
}

In addition to common properties of a view specification, a repeat specification has the following properties:

Property Type Description
repeat String[] | RepeatMapping

Required. Definition for fields to be repeated. One of: 1) An array of fields to be repeated. If "repeat" is an array, the field can be referred using {"repeat": "repeat"} 2) An object that mapped "row" and/or "column" to the listed of fields to be repeated along the particular orientations. The objects {"repeat": "row"} and {"repeat": "column"} can be used to refer to the repeated field respectively.

spec Spec

Required. A specification of the view that gets repeated.

columns Number

The number of columns to include in the view composition layout.

Default value: undefined – An infinite number of columns (a single row) will be assumed. This is equivalent to hconcat (for concat) and to using the column channel (for facet and repeat).

Note:

1) This property is only for:

  • the general (wrappable) concat operator (not hconcat/vconcat)
  • the facet and repeat operator with one field/repetition definition (without row/column nesting)

2) Setting the columns to 1 is equivalent to vconcat (for concat) and to using the row channel (for facet and repeat).

Row/Column Repeat Mapping

The repeat property can be an object with two optional properties ("row" and "column"), which define the list of fields that should be repeated into a row or column.

Property Type Description
row String[]

An array of fields to be repeated vertically.

column String[]

An array of fields to be repeated horizontally.

Examples

Repeated Line Charts

For instance, you can use this operator to quickly create an overview over the trends in multiple variables.

Note how the field for the y channel refers to a repeated field.

"y": {
  "field": {"repeat": "repeat"}
  ...
},

Repeated Histogram (Wrapped)

Scatterplot Matrix (SPLOM)

Repeat can be used to create a scatterplot matrix (SPLOM), where each cell shows a different 2D projection of the same data table. Here, we define both row and column.

You can also check the interactive SPLOM example.

Resolve

The default resolutions for repeat are independent scales and axes for position channels and shared scales and legends for all other channels. Currently, Vega-Lite does not support shared axes for repeated views.

Repeat Configuration

// Top-level View Specification
{
  ...,
  "config": { // Configuration Object

    "repeat": { // - Repeat Configuration
      "spacing": ...,
      "columns": ...,
    },
    ...
  }
}

The repeat configuration supports the following properties:

Property Type Description
columns Number

The number of columns to include in the view composition layout.

Default value: undefined – An infinite number of columns (a single row) will be assumed. This is equivalent to hconcat (for concat) and to using the column channel (for facet and repeat).

Note:

1) This property is only for:

  • the general (wrappable) concat operator (not hconcat/vconcat)
  • the facet and repeat operator with one field/repetition definition (without row/column nesting)

2) Setting the columns to 1 is equivalent to vconcat (for concat) and to using the row channel (for facet and repeat).

spacing Number

The default spacing in pixels between composed sub-views.

Default value: 20