# Mark display examples

Each section below is one complete track config for `LinearMarkDisplay`, the
picture it draws over a hosted file, and a link that opens the same view live.
The first ten read one file, UCSC's RepeatMasker Alu rows for hg38, whose
`milliDiv` column is a copy's divergence from its consensus; the rest read a BED
of read pairs, a set of copy-number BigWigs and a PAF of genome alignments. Copy
the config whose shape matches your file and change the field names.
[Mark display](https://jbrowse.org/jb2/docs/config_guides/mark_display) explains each slot.

## Bars from a column

`y` names the column, and the axis autoscales to what is on screen.

```json
{
  "type": "FeatureTrack",
  "trackId": "alu_bars",
  "name": "Alu divergence",
  "assemblyNames": ["hg38"],
  "adapter": {
    "type": "BedTabixAdapter",
    "uri": "https://jbrowse.org/demos/gene_density/Alu.bed.gz",
    "csi": true
  },
  "displays": [
    {
      "type": "LinearMarkDisplay",
      "displayId": "alu_bars-LinearMarkDisplay",
      "marks": [{ "mark": "bar", "encoding": { "y": "milliDiv" } }]
    }
  ]
}
```

CLI:

```bash
jbrowse add-track-json '{
  "type": "FeatureTrack",
  "trackId": "alu_bars",
  "name": "Alu divergence",
  "assemblyNames": ["hg38"],
  "adapter": {
    "type": "BedTabixAdapter",
    "uri": "https://jbrowse.org/demos/gene_density/Alu.bed.gz",
    "csi": true
  },
  "displays": [
    {
      "type": "LinearMarkDisplay",
      "displayId": "alu_bars-LinearMarkDisplay",
      "marks": [{ "mark": "bar", "encoding": { "y": "milliDiv" } }]
    }
  ]
}'
```

Opens on config <https://jbrowse.org/demos/gene_density/config.json> at `chr1:151,000,000-151,030,000`

<Figure src="/img/mark_display_examples/bars.png" caption="One bar per Alu copy over 30 kb of 1q21, its height the copy's divergence from its consensus." />

Session spec, on config <https://jbrowse.org/demos/gene_density/config.json>:

```json
{
  "sessionTracks": [
    {
      "type": "FeatureTrack",
      "trackId": "alu_bars",
      "name": "Alu divergence",
      "assemblyNames": [
        "hg38"
      ],
      "adapter": {
        "type": "BedTabixAdapter",
        "uri": "https://jbrowse.org/demos/gene_density/Alu.bed.gz",
        "csi": true
      },
      "displays": [
        {
          "type": "LinearMarkDisplay",
          "displayId": "alu_bars-LinearMarkDisplay",
          "marks": [
            {
              "mark": "bar",
              "encoding": {
                "y": "milliDiv"
              }
            }
          ]
        }
      ]
    }
  ],
  "views": [
    {
      "type": "LinearGenomeView",
      "assembly": "hg38",
      "loc": "chr1:151,000,000-151,030,000",
      "tracks": [
        {
          "trackId": "alu_bars",
          "height": 160
        }
      ]
    }
  ]
}
```

## Points, colored and shaped by a category

Each point stands at the middle of its copy. The color and the shape each take a
categorical scale over `strand`, whose values are `1` and `-1`, so
`scale.domain` names the levels and `scale.names` what the key calls them.

```json
{
  "type": "FeatureTrack",
  "trackId": "alu_points",
  "name": "Alu divergence by strand",
  "assemblyNames": ["hg38"],
  "adapter": {
    "type": "BedTabixAdapter",
    "uri": "https://jbrowse.org/demos/gene_density/Alu.bed.gz",
    "csi": true
  },
  "displays": [
    {
      "type": "LinearMarkDisplay",
      "displayId": "alu_points-LinearMarkDisplay",
      "marks": [
        {
          "mark": "point",
          "encoding": {
            "y": "milliDiv",
            "size": 8,
            "color": {
              "field": "strand",
              "scale": { "domain": ["1", "-1"], "names": ["+", "-"] },
              "legend": { "title": "Strand" }
            },
            "shape": {
              "field": "strand",
              "scale": {
                "domain": ["1", "-1"],
                "range": ["circle", "triangle-down"],
                "names": ["+", "-"]
              },
              "legend": { "title": "" }
            }
          }
        }
      ]
    }
  ]
}
```

CLI:

```bash
jbrowse add-track-json '{
  "type": "FeatureTrack",
  "trackId": "alu_points",
  "name": "Alu divergence by strand",
  "assemblyNames": ["hg38"],
  "adapter": {
    "type": "BedTabixAdapter",
    "uri": "https://jbrowse.org/demos/gene_density/Alu.bed.gz",
    "csi": true
  },
  "displays": [
    {
      "type": "LinearMarkDisplay",
      "displayId": "alu_points-LinearMarkDisplay",
      "marks": [
        {
          "mark": "point",
          "encoding": {
            "y": "milliDiv",
            "size": 8,
            "color": {
              "field": "strand",
              "scale": { "domain": ["1", "-1"], "names": ["+", "-"] },
              "legend": { "title": "Strand" }
            },
            "shape": {
              "field": "strand",
              "scale": {
                "domain": ["1", "-1"],
                "range": ["circle", "triangle-down"],
                "names": ["+", "-"]
              },
              "legend": { "title": "" }
            }
          }
        }
      ]
    }
  ]
}'
```

Opens on config <https://jbrowse.org/demos/gene_density/config.json> at `chr1:151,000,000-151,030,000`

<Figure src="/img/mark_display_examples/points.png" caption="The same copies as points, plus-strand copies as red circles and minus-strand copies as blue triangles." />

Session spec, on config <https://jbrowse.org/demos/gene_density/config.json>:

```json
{
  "sessionTracks": [
    {
      "type": "FeatureTrack",
      "trackId": "alu_points",
      "name": "Alu divergence by strand",
      "assemblyNames": [
        "hg38"
      ],
      "adapter": {
        "type": "BedTabixAdapter",
        "uri": "https://jbrowse.org/demos/gene_density/Alu.bed.gz",
        "csi": true
      },
      "displays": [
        {
          "type": "LinearMarkDisplay",
          "displayId": "alu_points-LinearMarkDisplay",
          "marks": [
            {
              "mark": "point",
              "encoding": {
                "y": "milliDiv",
                "size": 8,
                "color": {
                  "field": "strand",
                  "scale": {
                    "domain": [
                      "1",
                      "-1"
                    ],
                    "names": [
                      "+",
                      "-"
                    ]
                  },
                  "legend": {
                    "title": "Strand"
                  }
                },
                "shape": {
                  "field": "strand",
                  "scale": {
                    "domain": [
                      "1",
                      "-1"
                    ],
                    "range": [
                      "circle",
                      "triangle-down"
                    ],
                    "names": [
                      "+",
                      "-"
                    ]
                  },
                  "legend": {
                    "title": ""
                  }
                }
              }
            }
          ]
        }
      ]
    }
  ],
  "views": [
    {
      "type": "LinearGenomeView",
      "assembly": "hg38",
      "loc": "chr1:151,000,000-151,030,000",
      "tracks": [
        {
          "trackId": "alu_points",
          "height": 160
        }
      ]
    }
  ]
}
```

## A color ramp

A `linear` scale over the plotted column, pinned at both ends so the colors mean
the same in every window. `scale.scheme` names the ramp.

```json
{
  "type": "FeatureTrack",
  "trackId": "alu_ramp",
  "name": "Alu divergence, viridis",
  "assemblyNames": ["hg38"],
  "adapter": {
    "type": "BedTabixAdapter",
    "uri": "https://jbrowse.org/demos/gene_density/Alu.bed.gz",
    "csi": true
  },
  "displays": [
    {
      "type": "LinearMarkDisplay",
      "displayId": "alu_ramp-LinearMarkDisplay",
      "marks": [
        {
          "mark": "bar",
          "encoding": {
            "y": "milliDiv",
            "color": {
              "field": "milliDiv",
              "scale": {
                "type": "linear",
                "scheme": "viridis",
                "domainMin": 0,
                "domainMax": 300
              },
              "legend": { "title": "Divergence" }
            }
          }
        }
      ]
    }
  ]
}
```

CLI:

```bash
jbrowse add-track-json '{
  "type": "FeatureTrack",
  "trackId": "alu_ramp",
  "name": "Alu divergence, viridis",
  "assemblyNames": ["hg38"],
  "adapter": {
    "type": "BedTabixAdapter",
    "uri": "https://jbrowse.org/demos/gene_density/Alu.bed.gz",
    "csi": true
  },
  "displays": [
    {
      "type": "LinearMarkDisplay",
      "displayId": "alu_ramp-LinearMarkDisplay",
      "marks": [
        {
          "mark": "bar",
          "encoding": {
            "y": "milliDiv",
            "color": {
              "field": "milliDiv",
              "scale": {
                "type": "linear",
                "scheme": "viridis",
                "domainMin": 0,
                "domainMax": 300
              },
              "legend": { "title": "Divergence" }
            }
          }
        }
      ]
    }
  ]
}'
```

Opens on config <https://jbrowse.org/demos/gene_density/config.json> at `chr1:151,000,000-151,030,000`

<Figure src="/img/mark_display_examples/ramp.png" caption="Each bar colored by its own height through viridis, pinned from 0 to 300, with the ramp as the key." />

Session spec, on config <https://jbrowse.org/demos/gene_density/config.json>:

```json
{
  "sessionTracks": [
    {
      "type": "FeatureTrack",
      "trackId": "alu_ramp",
      "name": "Alu divergence, viridis",
      "assemblyNames": [
        "hg38"
      ],
      "adapter": {
        "type": "BedTabixAdapter",
        "uri": "https://jbrowse.org/demos/gene_density/Alu.bed.gz",
        "csi": true
      },
      "displays": [
        {
          "type": "LinearMarkDisplay",
          "displayId": "alu_ramp-LinearMarkDisplay",
          "marks": [
            {
              "mark": "bar",
              "encoding": {
                "y": "milliDiv",
                "color": {
                  "field": "milliDiv",
                  "scale": {
                    "type": "linear",
                    "scheme": "viridis",
                    "domainMin": 0,
                    "domainMax": 300
                  },
                  "legend": {
                    "title": "Divergence"
                  }
                }
              }
            }
          ]
        }
      ]
    }
  ],
  "views": [
    {
      "type": "LinearGenomeView",
      "assembly": "hg38",
      "loc": "chr1:151,000,000-151,030,000",
      "tracks": [
        {
          "trackId": "alu_ramp",
          "height": 160
        }
      ]
    }
  ]
}
```

## A color per interval

A `threshold` scale cuts the column at the values in `scale.domain` and paints
one `scale.range` color per interval, so a divergence reads as young, middle or
old.

```json
{
  "type": "FeatureTrack",
  "trackId": "alu_threshold",
  "name": "Alu age classes",
  "assemblyNames": ["hg38"],
  "adapter": {
    "type": "BedTabixAdapter",
    "uri": "https://jbrowse.org/demos/gene_density/Alu.bed.gz",
    "csi": true
  },
  "displays": [
    {
      "type": "LinearMarkDisplay",
      "displayId": "alu_threshold-LinearMarkDisplay",
      "marks": [
        {
          "mark": "bar",
          "encoding": {
            "y": "milliDiv",
            "color": {
              "field": "milliDiv",
              "scale": {
                "type": "threshold",
                "domain": [80, 150],
                "range": ["#d73027", "#fdae61", "#4575b4"]
              },
              "legend": { "title": "Divergence" }
            }
          }
        }
      ]
    }
  ]
}
```

CLI:

```bash
jbrowse add-track-json '{
  "type": "FeatureTrack",
  "trackId": "alu_threshold",
  "name": "Alu age classes",
  "assemblyNames": ["hg38"],
  "adapter": {
    "type": "BedTabixAdapter",
    "uri": "https://jbrowse.org/demos/gene_density/Alu.bed.gz",
    "csi": true
  },
  "displays": [
    {
      "type": "LinearMarkDisplay",
      "displayId": "alu_threshold-LinearMarkDisplay",
      "marks": [
        {
          "mark": "bar",
          "encoding": {
            "y": "milliDiv",
            "color": {
              "field": "milliDiv",
              "scale": {
                "type": "threshold",
                "domain": [80, 150],
                "range": ["#d73027", "#fdae61", "#4575b4"]
              },
              "legend": { "title": "Divergence" }
            }
          }
        }
      ]
    }
  ]
}'
```

Opens on config <https://jbrowse.org/demos/gene_density/config.json> at `chr1:151,000,000-151,030,000`

<Figure src="/img/mark_display_examples/threshold.png" caption="Bars under 80 in red, 80 to 150 in orange and 150 and over in blue, with the three intervals in the key." />

Session spec, on config <https://jbrowse.org/demos/gene_density/config.json>:

```json
{
  "sessionTracks": [
    {
      "type": "FeatureTrack",
      "trackId": "alu_threshold",
      "name": "Alu age classes",
      "assemblyNames": [
        "hg38"
      ],
      "adapter": {
        "type": "BedTabixAdapter",
        "uri": "https://jbrowse.org/demos/gene_density/Alu.bed.gz",
        "csi": true
      },
      "displays": [
        {
          "type": "LinearMarkDisplay",
          "displayId": "alu_threshold-LinearMarkDisplay",
          "marks": [
            {
              "mark": "bar",
              "encoding": {
                "y": "milliDiv",
                "color": {
                  "field": "milliDiv",
                  "scale": {
                    "type": "threshold",
                    "domain": [
                      80,
                      150
                    ],
                    "range": [
                      "#d73027",
                      "#fdae61",
                      "#4575b4"
                    ]
                  },
                  "legend": {
                    "title": "Divergence"
                  }
                }
              }
            }
          ]
        }
      ]
    }
  ],
  "views": [
    {
      "type": "LinearGenomeView",
      "assembly": "hg38",
      "loc": "chr1:151,000,000-151,030,000",
      "tracks": [
        {
          "trackId": "alu_threshold",
          "height": 160
        }
      ]
    }
  ]
}
```

## A histogram

A `bin` step snaps each copy to a bin four pixels wide at any zoom, and an
`aggregate` counts the copies in each. The bar plots the count without naming
it.

```json
{
  "type": "FeatureTrack",
  "trackId": "alu_histogram",
  "name": "Alu copies per bin",
  "assemblyNames": ["hg38"],
  "adapter": {
    "type": "BedTabixAdapter",
    "uri": "https://jbrowse.org/demos/gene_density/Alu.bed.gz",
    "csi": true
  },
  "displays": [
    {
      "type": "LinearMarkDisplay",
      "displayId": "alu_histogram-LinearMarkDisplay",
      "encoding": { "y": { "axis": { "title": "Copies per bin" } } },
      "marks": [
        {
          "mark": "bar",
          "transform": [
            { "type": "bin", "step": "auto" },
            { "type": "aggregate", "ops": [{ "op": "count" }] }
          ],
          "encoding": { "color": { "value": "#7f7f7f" } }
        }
      ]
    }
  ]
}
```

CLI:

```bash
jbrowse add-track-json '{
  "type": "FeatureTrack",
  "trackId": "alu_histogram",
  "name": "Alu copies per bin",
  "assemblyNames": ["hg38"],
  "adapter": {
    "type": "BedTabixAdapter",
    "uri": "https://jbrowse.org/demos/gene_density/Alu.bed.gz",
    "csi": true
  },
  "displays": [
    {
      "type": "LinearMarkDisplay",
      "displayId": "alu_histogram-LinearMarkDisplay",
      "encoding": { "y": { "axis": { "title": "Copies per bin" } } },
      "marks": [
        {
          "mark": "bar",
          "transform": [
            { "type": "bin", "step": "auto" },
            { "type": "aggregate", "ops": [{ "op": "count" }] }
          ],
          "encoding": { "color": { "value": "#7f7f7f" } }
        }
      ]
    }
  ]
}'
```

Opens on config <https://jbrowse.org/demos/gene_density/config.json> at `chr1:150,000,000-153,000,000`

<Figure src="/img/mark_display_examples/histogram.png" caption="Alu copies per bin across 3 Mb of 1q21, one grey bar per bin." />

Session spec, on config <https://jbrowse.org/demos/gene_density/config.json>:

```json
{
  "sessionTracks": [
    {
      "type": "FeatureTrack",
      "trackId": "alu_histogram",
      "name": "Alu copies per bin",
      "assemblyNames": [
        "hg38"
      ],
      "adapter": {
        "type": "BedTabixAdapter",
        "uri": "https://jbrowse.org/demos/gene_density/Alu.bed.gz",
        "csi": true
      },
      "displays": [
        {
          "type": "LinearMarkDisplay",
          "displayId": "alu_histogram-LinearMarkDisplay",
          "encoding": {
            "y": {
              "axis": {
                "title": "Copies per bin"
              }
            }
          },
          "marks": [
            {
              "mark": "bar",
              "transform": [
                {
                  "type": "bin",
                  "step": "auto"
                },
                {
                  "type": "aggregate",
                  "ops": [
                    {
                      "op": "count"
                    }
                  ]
                }
              ],
              "encoding": {
                "color": {
                  "value": "#7f7f7f"
                }
              }
            }
          ]
        }
      ]
    }
  ],
  "views": [
    {
      "type": "LinearGenomeView",
      "assembly": "hg38",
      "loc": "chr1:150,000,000-153,000,000",
      "tracks": [
        {
          "trackId": "alu_histogram",
          "height": 160
        }
      ]
    }
  ]
}
```

## A summary per bin

The histogram's bins show `mean` over the column in place of the count.

```json
{
  "type": "FeatureTrack",
  "trackId": "alu_mean",
  "name": "Mean Alu divergence per bin",
  "assemblyNames": ["hg38"],
  "adapter": {
    "type": "BedTabixAdapter",
    "uri": "https://jbrowse.org/demos/gene_density/Alu.bed.gz",
    "csi": true
  },
  "displays": [
    {
      "type": "LinearMarkDisplay",
      "displayId": "alu_mean-LinearMarkDisplay",
      "encoding": { "y": { "axis": { "title": "Mean divergence" } } },
      "marks": [
        {
          "mark": "bar",
          "transform": [
            { "type": "bin", "step": "auto" },
            {
              "type": "aggregate",
              "ops": [{ "op": "mean", "field": "milliDiv" }]
            }
          ],
          "encoding": { "color": { "value": "#7f7f7f" } }
        }
      ]
    }
  ]
}
```

CLI:

```bash
jbrowse add-track-json '{
  "type": "FeatureTrack",
  "trackId": "alu_mean",
  "name": "Mean Alu divergence per bin",
  "assemblyNames": ["hg38"],
  "adapter": {
    "type": "BedTabixAdapter",
    "uri": "https://jbrowse.org/demos/gene_density/Alu.bed.gz",
    "csi": true
  },
  "displays": [
    {
      "type": "LinearMarkDisplay",
      "displayId": "alu_mean-LinearMarkDisplay",
      "encoding": { "y": { "axis": { "title": "Mean divergence" } } },
      "marks": [
        {
          "mark": "bar",
          "transform": [
            { "type": "bin", "step": "auto" },
            {
              "type": "aggregate",
              "ops": [{ "op": "mean", "field": "milliDiv" }]
            }
          ],
          "encoding": { "color": { "value": "#7f7f7f" } }
        }
      ]
    }
  ]
}'
```

Opens on config <https://jbrowse.org/demos/gene_density/config.json> at `chr1:150,000,000-153,000,000`

<Figure src="/img/mark_display_examples/mean.png" caption="The mean divergence of the copies in each bin across the same 3 Mb." />

Session spec, on config <https://jbrowse.org/demos/gene_density/config.json>:

```json
{
  "sessionTracks": [
    {
      "type": "FeatureTrack",
      "trackId": "alu_mean",
      "name": "Mean Alu divergence per bin",
      "assemblyNames": [
        "hg38"
      ],
      "adapter": {
        "type": "BedTabixAdapter",
        "uri": "https://jbrowse.org/demos/gene_density/Alu.bed.gz",
        "csi": true
      },
      "displays": [
        {
          "type": "LinearMarkDisplay",
          "displayId": "alu_mean-LinearMarkDisplay",
          "encoding": {
            "y": {
              "axis": {
                "title": "Mean divergence"
              }
            }
          },
          "marks": [
            {
              "mark": "bar",
              "transform": [
                {
                  "type": "bin",
                  "step": "auto"
                },
                {
                  "type": "aggregate",
                  "ops": [
                    {
                      "op": "mean",
                      "field": "milliDiv"
                    }
                  ]
                }
              ],
              "encoding": {
                "color": {
                  "value": "#7f7f7f"
                }
              }
            }
          ]
        }
      ]
    }
  ],
  "views": [
    {
      "type": "LinearGenomeView",
      "assembly": "hg38",
      "loc": "chr1:150,000,000-153,000,000",
      "tracks": [
        {
          "trackId": "alu_mean",
          "height": 160
        }
      ]
    }
  ]
}
```

## A pileup

A `pileup` step writes each copy's row in a first-fit packing, and a `rect`
draws the packing, colored by strand.

```json
{
  "type": "FeatureTrack",
  "trackId": "alu_pileup",
  "name": "Alu copies, packed",
  "assemblyNames": ["hg38"],
  "adapter": {
    "type": "BedTabixAdapter",
    "uri": "https://jbrowse.org/demos/gene_density/Alu.bed.gz",
    "csi": true
  },
  "displays": [
    {
      "type": "LinearMarkDisplay",
      "displayId": "alu_pileup-LinearMarkDisplay",
      "marks": [
        {
          "mark": "rect",
          "transform": [{ "type": "pileup", "padding": 200 }],
          "encoding": {
            "color": {
              "field": "strand",
              "scale": { "domain": ["1", "-1"], "names": ["+", "-"] },
              "legend": { "title": "Strand" }
            }
          }
        }
      ]
    }
  ]
}
```

CLI:

```bash
jbrowse add-track-json '{
  "type": "FeatureTrack",
  "trackId": "alu_pileup",
  "name": "Alu copies, packed",
  "assemblyNames": ["hg38"],
  "adapter": {
    "type": "BedTabixAdapter",
    "uri": "https://jbrowse.org/demos/gene_density/Alu.bed.gz",
    "csi": true
  },
  "displays": [
    {
      "type": "LinearMarkDisplay",
      "displayId": "alu_pileup-LinearMarkDisplay",
      "marks": [
        {
          "mark": "rect",
          "transform": [{ "type": "pileup", "padding": 200 }],
          "encoding": {
            "color": {
              "field": "strand",
              "scale": { "domain": ["1", "-1"], "names": ["+", "-"] },
              "legend": { "title": "Strand" }
            }
          }
        }
      ]
    }
  ]
}'
```

Opens on config <https://jbrowse.org/demos/gene_density/config.json> at `chr1:151,000,000-151,030,000`

<Figure src="/img/mark_display_examples/pileup.png" caption="The copies stacked into rows with 200 bp between neighbours, plus strand in red and minus strand in blue." />

Session spec, on config <https://jbrowse.org/demos/gene_density/config.json>:

```json
{
  "sessionTracks": [
    {
      "type": "FeatureTrack",
      "trackId": "alu_pileup",
      "name": "Alu copies, packed",
      "assemblyNames": [
        "hg38"
      ],
      "adapter": {
        "type": "BedTabixAdapter",
        "uri": "https://jbrowse.org/demos/gene_density/Alu.bed.gz",
        "csi": true
      },
      "displays": [
        {
          "type": "LinearMarkDisplay",
          "displayId": "alu_pileup-LinearMarkDisplay",
          "marks": [
            {
              "mark": "rect",
              "transform": [
                {
                  "type": "pileup",
                  "padding": 200
                }
              ],
              "encoding": {
                "color": {
                  "field": "strand",
                  "scale": {
                    "domain": [
                      "1",
                      "-1"
                    ],
                    "names": [
                      "+",
                      "-"
                    ]
                  },
                  "legend": {
                    "title": "Strand"
                  }
                }
              }
            }
          ]
        }
      ]
    }
  ],
  "views": [
    {
      "type": "LinearGenomeView",
      "assembly": "hg38",
      "loc": "chr1:151,000,000-151,030,000",
      "tracks": [
        {
          "trackId": "alu_pileup",
          "height": 160
        }
      ]
    }
  ]
}
```

## A facet

`facet` splits the copies on a field and stacks one section per value under a
chip. A `pileup` in the facet's `transform` packs each section separately.

```json
{
  "type": "FeatureTrack",
  "trackId": "alu_facet",
  "name": "Alu copies by strand",
  "assemblyNames": ["hg38"],
  "adapter": {
    "type": "BedTabixAdapter",
    "uri": "https://jbrowse.org/demos/gene_density/Alu.bed.gz",
    "csi": true
  },
  "displays": [
    {
      "type": "LinearMarkDisplay",
      "displayId": "alu_facet-LinearMarkDisplay",
      "facet": { "field": "strand", "transform": [{ "type": "pileup" }] },
      "marks": [
        { "mark": "rect", "encoding": { "color": { "value": "#4575b4" } } }
      ]
    }
  ]
}
```

CLI:

```bash
jbrowse add-track-json '{
  "type": "FeatureTrack",
  "trackId": "alu_facet",
  "name": "Alu copies by strand",
  "assemblyNames": ["hg38"],
  "adapter": {
    "type": "BedTabixAdapter",
    "uri": "https://jbrowse.org/demos/gene_density/Alu.bed.gz",
    "csi": true
  },
  "displays": [
    {
      "type": "LinearMarkDisplay",
      "displayId": "alu_facet-LinearMarkDisplay",
      "facet": { "field": "strand", "transform": [{ "type": "pileup" }] },
      "marks": [
        { "mark": "rect", "encoding": { "color": { "value": "#4575b4" } } }
      ]
    }
  ]
}'
```

Opens on config <https://jbrowse.org/demos/gene_density/config.json> at `chr1:151,000,000-151,030,000`

<Figure src="/img/mark_display_examples/facet.png" caption="Plus-strand copies packed in one section and minus-strand copies in another, each under a chip naming its strand." />

Session spec, on config <https://jbrowse.org/demos/gene_density/config.json>:

```json
{
  "sessionTracks": [
    {
      "type": "FeatureTrack",
      "trackId": "alu_facet",
      "name": "Alu copies by strand",
      "assemblyNames": [
        "hg38"
      ],
      "adapter": {
        "type": "BedTabixAdapter",
        "uri": "https://jbrowse.org/demos/gene_density/Alu.bed.gz",
        "csi": true
      },
      "displays": [
        {
          "type": "LinearMarkDisplay",
          "displayId": "alu_facet-LinearMarkDisplay",
          "facet": {
            "field": "strand",
            "transform": [
              {
                "type": "pileup"
              }
            ]
          },
          "marks": [
            {
              "mark": "rect",
              "encoding": {
                "color": {
                  "value": "#4575b4"
                }
              }
            }
          ]
        }
      ]
    }
  ],
  "views": [
    {
      "type": "LinearGenomeView",
      "assembly": "hg38",
      "loc": "chr1:151,000,000-151,030,000",
      "tracks": [
        {
          "trackId": "alu_facet",
          "height": 200
        }
      ]
    }
  ]
}
```

## Labels

A `text` mark prints a field over each feature, culled where two labels would
overlap. `maxBpPerPx` stops the labels once the view is too wide to read them.

```json
{
  "type": "FeatureTrack",
  "trackId": "alu_labels",
  "name": "Alu divergence, labelled",
  "assemblyNames": ["hg38"],
  "adapter": {
    "type": "BedTabixAdapter",
    "uri": "https://jbrowse.org/demos/gene_density/Alu.bed.gz",
    "csi": true
  },
  "displays": [
    {
      "type": "LinearMarkDisplay",
      "displayId": "alu_labels-LinearMarkDisplay",
      "marks": [
        {
          "mark": "bar",
          "encoding": { "y": "milliDiv", "color": { "value": "#c8d8ee" } }
        },
        {
          "mark": "text",
          "encoding": { "y": "milliDiv", "text": "name" },
          "maxBpPerPx": 50
        }
      ]
    }
  ]
}
```

CLI:

```bash
jbrowse add-track-json '{
  "type": "FeatureTrack",
  "trackId": "alu_labels",
  "name": "Alu divergence, labelled",
  "assemblyNames": ["hg38"],
  "adapter": {
    "type": "BedTabixAdapter",
    "uri": "https://jbrowse.org/demos/gene_density/Alu.bed.gz",
    "csi": true
  },
  "displays": [
    {
      "type": "LinearMarkDisplay",
      "displayId": "alu_labels-LinearMarkDisplay",
      "marks": [
        {
          "mark": "bar",
          "encoding": { "y": "milliDiv", "color": { "value": "#c8d8ee" } }
        },
        {
          "mark": "text",
          "encoding": { "y": "milliDiv", "text": "name" },
          "maxBpPerPx": 50
        }
      ]
    }
  ]
}'
```

Opens on config <https://jbrowse.org/demos/gene_density/config.json> at `chr1:151,000,000-151,030,000`

<Figure src="/img/mark_display_examples/labels.png" caption="Each bar with its subfamily name over it, the names that would overlap a neighbour left out." />

Session spec, on config <https://jbrowse.org/demos/gene_density/config.json>:

```json
{
  "sessionTracks": [
    {
      "type": "FeatureTrack",
      "trackId": "alu_labels",
      "name": "Alu divergence, labelled",
      "assemblyNames": [
        "hg38"
      ],
      "adapter": {
        "type": "BedTabixAdapter",
        "uri": "https://jbrowse.org/demos/gene_density/Alu.bed.gz",
        "csi": true
      },
      "displays": [
        {
          "type": "LinearMarkDisplay",
          "displayId": "alu_labels-LinearMarkDisplay",
          "marks": [
            {
              "mark": "bar",
              "encoding": {
                "y": "milliDiv",
                "color": {
                  "value": "#c8d8ee"
                }
              }
            },
            {
              "mark": "text",
              "encoding": {
                "y": "milliDiv",
                "text": "name"
              },
              "maxBpPerPx": 50
            }
          ]
        }
      ]
    }
  ],
  "views": [
    {
      "type": "LinearGenomeView",
      "assembly": "hg38",
      "loc": "chr1:151,000,000-151,030,000",
      "tracks": [
        {
          "trackId": "alu_labels",
          "height": 160
        }
      ]
    }
  ]
}
```

## Reference lines and an axis title

`encoding.y` holds the guides a reader checks a plot against: `rules`, lines at
chosen values, and `title`, the caption beside the axis.

```json
{
  "type": "FeatureTrack",
  "trackId": "alu_rules",
  "name": "Alu divergence, with rules",
  "assemblyNames": ["hg38"],
  "adapter": {
    "type": "BedTabixAdapter",
    "uri": "https://jbrowse.org/demos/gene_density/Alu.bed.gz",
    "csi": true
  },
  "displays": [
    {
      "type": "LinearMarkDisplay",
      "displayId": "alu_rules-LinearMarkDisplay",
      "encoding": {
        "y": {
          "axis": { "title": "Divergence, per mille" },
          "rules": [{ "value": 80, "color": "#d73027", "label": "young" }, 150]
        }
      },
      "marks": [{ "mark": "bar", "encoding": { "y": "milliDiv" } }]
    }
  ]
}
```

CLI:

```bash
jbrowse add-track-json '{
  "type": "FeatureTrack",
  "trackId": "alu_rules",
  "name": "Alu divergence, with rules",
  "assemblyNames": ["hg38"],
  "adapter": {
    "type": "BedTabixAdapter",
    "uri": "https://jbrowse.org/demos/gene_density/Alu.bed.gz",
    "csi": true
  },
  "displays": [
    {
      "type": "LinearMarkDisplay",
      "displayId": "alu_rules-LinearMarkDisplay",
      "encoding": {
        "y": {
          "axis": { "title": "Divergence, per mille" },
          "rules": [{ "value": 80, "color": "#d73027", "label": "young" }, 150]
        }
      },
      "marks": [{ "mark": "bar", "encoding": { "y": "milliDiv" } }]
    }
  ]
}'
```

Opens on config <https://jbrowse.org/demos/gene_density/config.json> at `chr1:151,000,000-151,030,000`

<Figure src="/img/mark_display_examples/rules.png" caption="The bars under a labelled red rule at 80 and a grey one at 150, with the axis captioned." />

Session spec, on config <https://jbrowse.org/demos/gene_density/config.json>:

```json
{
  "sessionTracks": [
    {
      "type": "FeatureTrack",
      "trackId": "alu_rules",
      "name": "Alu divergence, with rules",
      "assemblyNames": [
        "hg38"
      ],
      "adapter": {
        "type": "BedTabixAdapter",
        "uri": "https://jbrowse.org/demos/gene_density/Alu.bed.gz",
        "csi": true
      },
      "displays": [
        {
          "type": "LinearMarkDisplay",
          "displayId": "alu_rules-LinearMarkDisplay",
          "encoding": {
            "y": {
              "axis": {
                "title": "Divergence, per mille"
              },
              "rules": [
                {
                  "value": 80,
                  "color": "#d73027",
                  "label": "young"
                },
                150
              ]
            }
          },
          "marks": [
            {
              "mark": "bar",
              "encoding": {
                "y": "milliDiv"
              }
            }
          ]
        }
      ]
    }
  ],
  "views": [
    {
      "type": "LinearGenomeView",
      "assembly": "hg38",
      "loc": "chr1:151,000,000-151,030,000",
      "tracks": [
        {
          "trackId": "alu_rules",
          "height": 160
        }
      ]
    }
  ]
}
```

## Links

A `link` draws a curve from `x` to `x2`. Over a BED of read pairs, each row
running from the leftmost read to the far end of its insert, that is one arc per
pair, stroked by its mapping quality.

```json
{
  "type": "FeatureTrack",
  "trackId": "pair_links",
  "name": "NA12878 pairs over 1 kb, as arcs",
  "assemblyNames": ["hg38"],
  "adapter": {
    "type": "BedTabixAdapter",
    "uri": "https://jbrowse.org/demos/read_marks/NA12878.chr20.discordant_pairs.bed.gz",
    "csi": true
  },
  "displays": [
    {
      "type": "LinearMarkDisplay",
      "displayId": "pair_links-LinearMarkDisplay",
      "marks": [
        {
          "mark": "link",
          "transform": [
            { "type": "filter", "expr": "jexl:feature.tlen < 20000" }
          ],
          "encoding": {
            "color": {
              "field": "score",
              "scale": {
                "type": "linear",
                "domainMin": 0,
                "domainMax": 60,
                "range": ["#bdbdbd", "#1f4e9a"]
              },
              "legend": { "title": "Mapping quality" }
            }
          }
        }
      ]
    }
  ]
}
```

CLI:

```bash
jbrowse add-track-json '{
  "type": "FeatureTrack",
  "trackId": "pair_links",
  "name": "NA12878 pairs over 1 kb, as arcs",
  "assemblyNames": ["hg38"],
  "adapter": {
    "type": "BedTabixAdapter",
    "uri": "https://jbrowse.org/demos/read_marks/NA12878.chr20.discordant_pairs.bed.gz",
    "csi": true
  },
  "displays": [
    {
      "type": "LinearMarkDisplay",
      "displayId": "pair_links-LinearMarkDisplay",
      "marks": [
        {
          "mark": "link",
          "transform": [
            { "type": "filter", "expr": "jexl:feature.tlen < 20000" }
          ],
          "encoding": {
            "color": {
              "field": "score",
              "scale": {
                "type": "linear",
                "domainMin": 0,
                "domainMax": 60,
                "range": ["#bdbdbd", "#1f4e9a"]
              },
              "legend": { "title": "Mapping quality" }
            }
          }
        }
      ]
    }
  ]
}'
```

Opens on config <https://jbrowse.org/demos/read_marks/config.json> at `chr20:32,925,000-32,955,000`

<Figure src="/img/mark_display_examples/links.png" caption="Pairs across a deletion, each an arc stroked by its mapping quality." />

Session spec, on config <https://jbrowse.org/demos/read_marks/config.json>:

```json
{
  "sessionTracks": [
    {
      "type": "FeatureTrack",
      "trackId": "pair_links",
      "name": "NA12878 pairs over 1 kb, as arcs",
      "assemblyNames": [
        "hg38"
      ],
      "adapter": {
        "type": "BedTabixAdapter",
        "uri": "https://jbrowse.org/demos/read_marks/NA12878.chr20.discordant_pairs.bed.gz",
        "csi": true
      },
      "displays": [
        {
          "type": "LinearMarkDisplay",
          "displayId": "pair_links-LinearMarkDisplay",
          "marks": [
            {
              "mark": "link",
              "transform": [
                {
                  "type": "filter",
                  "expr": "jexl:feature.tlen < 20000"
                }
              ],
              "encoding": {
                "color": {
                  "field": "score",
                  "scale": {
                    "type": "linear",
                    "domainMin": 0,
                    "domainMax": 60,
                    "range": [
                      "#bdbdbd",
                      "#1f4e9a"
                    ]
                  },
                  "legend": {
                    "title": "Mapping quality"
                  }
                }
              }
            }
          ]
        }
      ]
    }
  ],
  "views": [
    {
      "type": "LinearGenomeView",
      "assembly": "hg38",
      "loc": "chr20:32,925,000-32,955,000",
      "tracks": [
        {
          "trackId": "pair_links",
          "height": 160
        }
      ]
    }
  ]
}
```

## One row per file

Over a multi-BigWig, `rows: "source"` gives each file a row on one shared axis,
with the row labels, **Sort rows by value here** and **Cluster rows by
similarity...** in the track menu.

```json
{
  "type": "MultiQuantitativeTrack",
  "trackId": "pur_cnv_rows",
  "name": "Copy number, six PUR individuals",
  "assemblyNames": ["hg38"],
  "adapter": {
    "type": "MultiWiggleAdapter",
    "bigWigs": [
      "https://jbrowse.org/genomes/GRCh38/1000g/kidd_lab_cnv/PUR/HG01177.qm2.CN.1k.bw",
      "https://jbrowse.org/genomes/GRCh38/1000g/kidd_lab_cnv/PUR/HG01083.qm2.CN.1k.bw",
      "https://jbrowse.org/genomes/GRCh38/1000g/kidd_lab_cnv/PUR/HG01070.qm2.CN.1k.bw",
      "https://jbrowse.org/genomes/GRCh38/1000g/kidd_lab_cnv/PUR/HG01395.qm2.CN.1k.bw",
      "https://jbrowse.org/genomes/GRCh38/1000g/kidd_lab_cnv/PUR/HG00731.qm2.CN.1k.bw",
      "https://jbrowse.org/genomes/GRCh38/1000g/kidd_lab_cnv/PUR/HG00553.qm2.CN.1k.bw"
    ]
  },
  "displays": [
    {
      "type": "LinearMarkDisplay",
      "displayId": "pur_cnv_rows-LinearMarkDisplay",
      "rows": "source",
      "encoding": {
        "y": {
          "scale": { "domainMin": 0, "domainMax": 10 },
          "axis": { "title": "Copies" }
        }
      },
      "marks": [
        {
          "mark": "bar",
          "encoding": { "y": "score", "color": { "value": "#4575b4" } }
        }
      ]
    }
  ]
}
```

CLI:

```bash
jbrowse add-track-json '{
  "type": "MultiQuantitativeTrack",
  "trackId": "pur_cnv_rows",
  "name": "Copy number, six PUR individuals",
  "assemblyNames": ["hg38"],
  "adapter": {
    "type": "MultiWiggleAdapter",
    "bigWigs": [
      "https://jbrowse.org/genomes/GRCh38/1000g/kidd_lab_cnv/PUR/HG01177.qm2.CN.1k.bw",
      "https://jbrowse.org/genomes/GRCh38/1000g/kidd_lab_cnv/PUR/HG01083.qm2.CN.1k.bw",
      "https://jbrowse.org/genomes/GRCh38/1000g/kidd_lab_cnv/PUR/HG01070.qm2.CN.1k.bw",
      "https://jbrowse.org/genomes/GRCh38/1000g/kidd_lab_cnv/PUR/HG01395.qm2.CN.1k.bw",
      "https://jbrowse.org/genomes/GRCh38/1000g/kidd_lab_cnv/PUR/HG00731.qm2.CN.1k.bw",
      "https://jbrowse.org/genomes/GRCh38/1000g/kidd_lab_cnv/PUR/HG00553.qm2.CN.1k.bw"
    ]
  },
  "displays": [
    {
      "type": "LinearMarkDisplay",
      "displayId": "pur_cnv_rows-LinearMarkDisplay",
      "rows": "source",
      "encoding": {
        "y": {
          "scale": { "domainMin": 0, "domainMax": 10 },
          "axis": { "title": "Copies" }
        }
      },
      "marks": [
        {
          "mark": "bar",
          "encoding": { "y": "score", "color": { "value": "#4575b4" } }
        }
      ]
    }
  ]
}'
```

Opens on config <https://jbrowse.org/demos/gene_density/config.json> at `chr17:36,193,000-36,198,000`

<Figure src="/img/mark_display_examples/rows.png" caption="Six individuals' copy number over CCL3L1, one row per file on a shared axis." />

Session spec, on config <https://jbrowse.org/demos/gene_density/config.json>:

```json
{
  "sessionTracks": [
    {
      "type": "MultiQuantitativeTrack",
      "trackId": "pur_cnv_rows",
      "name": "Copy number, six PUR individuals",
      "assemblyNames": [
        "hg38"
      ],
      "adapter": {
        "type": "MultiWiggleAdapter",
        "bigWigs": [
          "https://jbrowse.org/genomes/GRCh38/1000g/kidd_lab_cnv/PUR/HG01177.qm2.CN.1k.bw",
          "https://jbrowse.org/genomes/GRCh38/1000g/kidd_lab_cnv/PUR/HG01083.qm2.CN.1k.bw",
          "https://jbrowse.org/genomes/GRCh38/1000g/kidd_lab_cnv/PUR/HG01070.qm2.CN.1k.bw",
          "https://jbrowse.org/genomes/GRCh38/1000g/kidd_lab_cnv/PUR/HG01395.qm2.CN.1k.bw",
          "https://jbrowse.org/genomes/GRCh38/1000g/kidd_lab_cnv/PUR/HG00731.qm2.CN.1k.bw",
          "https://jbrowse.org/genomes/GRCh38/1000g/kidd_lab_cnv/PUR/HG00553.qm2.CN.1k.bw"
        ]
      },
      "displays": [
        {
          "type": "LinearMarkDisplay",
          "displayId": "pur_cnv_rows-LinearMarkDisplay",
          "rows": "source",
          "encoding": {
            "y": {
              "scale": {
                "domainMin": 0,
                "domainMax": 10
              },
              "axis": {
                "title": "Copies"
              }
            }
          },
          "marks": [
            {
              "mark": "bar",
              "encoding": {
                "y": "score",
                "color": {
                  "value": "#4575b4"
                }
              }
            }
          ]
        }
      ]
    }
  ],
  "views": [
    {
      "type": "LinearGenomeView",
      "assembly": "hg38",
      "loc": "chr17:36,193,000-36,198,000",
      "tracks": [
        {
          "trackId": "pur_cnv_rows",
          "height": 300
        }
      ]
    }
  ]
}
```

## Percent identity along an alignment

A PAF's `SyntenyTrack` takes the mark display too. Each alignment's `identity`
comes from minimap2's `de` divergence tag, or from its match count over its
alignment length in a PAF without one. A `rule` at that value across each
alignment is a percent identity plot, the picture
[PipMaker](https://doi.org/10.1101/gr.10.4.577) drew for a pair of genomes.
Stretches with no rule are where nothing aligned. Coloring each rule by the same
value separates short alignments that overlap, and `legend.show` is off because
the axis already reads the color.

```json
{
  "type": "SyntenyTrack",
  "trackId": "hpylori_identity",
  "name": "26695 against J99, percent identity",
  "assemblyNames": ["GCF_000982695.1", "GCF_000307795.1"],
  "adapter": {
    "type": "PairwiseIndexedPAFAdapter",
    "uri": "https://jbrowse.org/demos/hpylori/26695_vs_j99.pif.gz",
    "assemblyNames": ["GCF_000982695.1", "GCF_000307795.1"]
  },
  "displays": [
    {
      "type": "LinearMarkDisplay",
      "displayId": "hpylori_identity-LinearMarkDisplay",
      "legend": { "show": false },
      "encoding": {
        "y": {
          "scale": { "domainMin": 0.5, "domainMax": 1 },
          "axis": { "title": "Identity" }
        }
      },
      "marks": [
        {
          "mark": "rule",
          "encoding": {
            "y": "identity",
            "strokeWidth": 4,
            "color": {
              "field": "identity",
              "scale": {
                "type": "linear",
                "scheme": "viridis",
                "domainMin": 0.7,
                "domainMax": 1
              },
              "legend": { "title": "Identity" }
            }
          }
        }
      ]
    }
  ]
}
```

CLI:

```bash
jbrowse add-track-json '{
  "type": "SyntenyTrack",
  "trackId": "hpylori_identity",
  "name": "26695 against J99, percent identity",
  "assemblyNames": ["GCF_000982695.1", "GCF_000307795.1"],
  "adapter": {
    "type": "PairwiseIndexedPAFAdapter",
    "uri": "https://jbrowse.org/demos/hpylori/26695_vs_j99.pif.gz",
    "assemblyNames": ["GCF_000982695.1", "GCF_000307795.1"]
  },
  "displays": [
    {
      "type": "LinearMarkDisplay",
      "displayId": "hpylori_identity-LinearMarkDisplay",
      "legend": { "show": false },
      "encoding": {
        "y": {
          "scale": { "domainMin": 0.5, "domainMax": 1 },
          "axis": { "title": "Identity" }
        }
      },
      "marks": [
        {
          "mark": "rule",
          "encoding": {
            "y": "identity",
            "strokeWidth": 4,
            "color": {
              "field": "identity",
              "scale": {
                "type": "linear",
                "scheme": "viridis",
                "domainMin": 0.7,
                "domainMax": 1
              },
              "legend": { "title": "Identity" }
            }
          }
        }
      ]
    }
  ]
}'
```

Opens on config <https://jbrowse.org/demos/hpylori/config.json> at `NC_018939.1:330,000-560,000`

<Figure src="/img/mark_display_examples/identity.png" caption="H. pylori 26695 against J99, one line per alignment at its identity and colored by it." />

Session spec, on config <https://jbrowse.org/demos/hpylori/config.json>:

```json
{
  "sessionTracks": [
    {
      "type": "SyntenyTrack",
      "trackId": "hpylori_identity",
      "name": "26695 against J99, percent identity",
      "assemblyNames": [
        "GCF_000982695.1",
        "GCF_000307795.1"
      ],
      "adapter": {
        "type": "PairwiseIndexedPAFAdapter",
        "uri": "https://jbrowse.org/demos/hpylori/26695_vs_j99.pif.gz",
        "assemblyNames": [
          "GCF_000982695.1",
          "GCF_000307795.1"
        ]
      },
      "displays": [
        {
          "type": "LinearMarkDisplay",
          "displayId": "hpylori_identity-LinearMarkDisplay",
          "legend": {
            "show": false
          },
          "encoding": {
            "y": {
              "scale": {
                "domainMin": 0.5,
                "domainMax": 1
              },
              "axis": {
                "title": "Identity"
              }
            }
          },
          "marks": [
            {
              "mark": "rule",
              "encoding": {
                "y": "identity",
                "strokeWidth": 4,
                "color": {
                  "field": "identity",
                  "scale": {
                    "type": "linear",
                    "scheme": "viridis",
                    "domainMin": 0.7,
                    "domainMax": 1
                  },
                  "legend": {
                    "title": "Identity"
                  }
                }
              }
            }
          ]
        }
      ]
    }
  ],
  "views": [
    {
      "type": "LinearGenomeView",
      "assembly": "GCF_000307795.1",
      "loc": "NC_018939.1:330,000-560,000",
      "tracks": [
        {
          "trackId": "hpylori_identity",
          "height": 200
        }
      ]
    }
  ]
}
```

A PAF line has one identity for the whole alignment, so a long alignment draws
as one flat line however its identity varies along its length. An all-vs-all PAF
gives one row per genome, which
[the all-vs-all synteny tutorial](https://jbrowse.org/jb2/docs/tutorials/allvsall_synteny#percent-identity-per-strain)
walks through.

## More

[Mark display](https://jbrowse.org/jb2/docs/config_guides/mark_display) shows a density and the raw features in one
track across zooms and a facet over a BAM's haplotype tag;
[A grammar of graphics over a BED (RepeatMasker Alu age)](https://jbrowse.org/jb2/docs/tutorials/alu_age) and [A grammar of graphics over a BAM (NA12878 insert size)](https://jbrowse.org/jb2/docs/tutorials/read_marks) each work through
one file to answer one question.

