Stack¶
The "stack" transform computes a stacked layout. Stacked bar plots and
sequence logos are some of its
applications.
Parameters¶
asRequired- Type: array
Fields to write the stacked values.
Default:
["y0", "y1"] baseField- Type: string (field name)
The field that contains the base or amino acid. Used for information content calculation when the offset is
"information". The data objects that havenullin the baseField are considered gaps and they are taken into account when scaling the the locus' information content. cardinality- Type: number
Cardinality, e.g., the number if distinct bases or amino acids. Used for information content calculation when the offset is
"information".Default:
4 field- Type: string (field name)
The field to stack. If no field is defined, a constant value of one is assumed.
groupbyRequired- Type: array
The fields to be used for forming groups for different stacks.
offset- Type: string
How to offset the values in a stack.
"zero"(default) starts stacking at 0."center"centers the values around zero."normalize"computes intra-stack percentages and normalizes the values to the range of[0, 1]."information"computes a layout for a sequence logo. The total height of the stack reflects the group's information content. sort- Type: CompareParams
The sort order of data in each stack.
Examples¶
Stacked bar plot¶
{
"data": {
"values": [
{ "x": 1, "q": "A", "z": 7 },
{ "x": 1, "q": "B", "z": 3 },
{ "x": 1, "q": "C", "z": 10 },
{ "x": 2, "q": "A", "z": 8 },
{ "x": 2, "q": "B", "z": 5 },
{ "x": 3, "q": "B", "z": 10 }
]
},
"transform": [
{
"type": "stack",
"field": "z",
"groupby": ["x"]
}
],
"mark": "rect",
"encoding": {
"x": { "field": "x", "type": "nominal", "band": 0.8 },
"y": { "field": "y0", "type": "quantitative" },
"y2": { "field": "y1" },
"color": { "field": "q", "type": "nominal" }
}
}
Sequence logo¶
{
"data": {
"values": [
{ "pos": 1, "base": "A", "count": 2 },
{ "pos": 1, "base": "C", "count": 3 },
{ "pos": 1, "base": "T", "count": 5 },
{ "pos": 2, "base": "A", "count": 7 },
{ "pos": 2, "base": "C", "count": 3 },
{ "pos": 3, "base": "A", "count": 10 },
{ "pos": 4, "base": "T", "count": 9 },
{ "pos": 4, "base": "G", "count": 1 },
{ "pos": 5, "base": "G", "count": 8 },
{ "pos": 6, "base": "G", "count": 7 }
]
},
"transform": [
{
"type": "stack",
"field": "count",
"groupby": ["pos"],
"offset": "information",
"as": ["_y0", "_y1"],
"baseField": "base",
"sort": { "field": "count", "order": "ascending" }
}
],
"encoding": {
"x": { "field": "pos", "type": "index" },
"y": {
"field": "_y0",
"type": "quantitative",
"scale": { "domain": [0, 2] },
"title": "Information"
},
"y2": { "field": "_y1" },
"text": { "field": "base", "type": "nominal" },
"color": {
"field": "base",
"type": "nominal",
"scale": {
"type": "ordinal",
"domain": ["A", "C", "T", "G"],
"range": ["#7BD56C", "#FF9B9B", "#86BBF1", "#FFC56C"]
}
}
},
"mark": {
"type": "text",
"font": "Source Sans Pro",
"fontWeight": 700,
"size": 100,
"squeeze": true,
"fitToBand": true,
"paddingX": 0,
"paddingY": 0,
"logoLetters": true
}
}