Constructs a SeqLegendSpec object that describes where and how a legend
group should be rendered. The spec captures placement intent only — no
rendering logic is executed here. It is consumed by the legend-rendering
layer in a later batch.
Usage
seq_legend(
keys,
title = NULL,
position = "inside",
x = 0.5,
y = 0.5,
hjust = 0,
orientation = NULL,
nrow = NULL,
ncol = NULL,
side = NULL
)Arguments
- keys
A single
LegendKey, or a named or unnamed list ofLegendKeyobjects. Required.- title
Optional character string. The legend group title drawn above or beside the key block.
- position
Character. One of
"inside","track_margin", or"canvas_margin". Controls which area the legend occupies. Default"inside".- x
Numeric in [0, 1]. Horizontal position of the legend anchor within the target area. Default
0.5.- y
Numeric in [0, 1]. Vertical position of the legend anchor within the target area. Default
0.5.- hjust
Numeric in [0, 1]. Horizontal justification of the legend content block relative to the anchor.
0= left-aligned,1= right-aligned. Default0.- orientation
Character. One of
"horizontal"or"vertical". Controls whether keys are laid out as a row or a column. WhenNULL(default), orientation is inferred fromside:"vertical"forside %in% c("left", "right"),"horizontal"otherwise.- nrow
Integer or
NULL. Number of rows in the key grid. When bothnrowandncolareNULL, defaults to 1 row (all keys in one row for horizontal orientation) or 1 column (all keys in one column for vertical orientation).- ncol
Integer or
NULL. Number of columns in the key grid.- side
Character or
NULL. Forposition %in% c("track_margin", "canvas_margin"), which margin to target. One of"top","bottom","left","right". WhenNULL, defaults to"top"for margin positions and is leftNULLfor"inside".
Examples
k1 <- LegendKey(label = "H3K27ac", color = "firebrick")
k2 <- LegendKey(label = "H3K4me3", color = "steelblue")
# Inside the track, top-left
spec <- seq_legend(list(k1, k2), title = "Marks", x = 0.02, y = 0.95)
# In the outer track margin, bottom
spec <- seq_legend(list(k1, k2), position = "track_margin", side = "bottom")