A hierarchical treemap of gene-set / pathway composition. The hierarchy is
built from a flat edge list with d3-hierarchy
(stratify + treemap) and tiles are rendered on a canvas so thousands of
leaves stay interactive; tile labels and a drill-down breadcrumb are drawn as
a crisp vector overlay. Click a tile to zoom into that node and the
breadcrumb to zoom back out.
Arguments
- data
A data frame describing a tree as an edge list. Required columns:
id(unique node id) andparent(id of the parent; the root's parent isNAor""). A numericvaluecolumn supplies leaf weights. A group's size is the sum of its leaves; a value given on an internal node is ignored. Without avaluecolumn every leaf weighs 1, so tiles show leaf counts. An optionallabelcolumn supplies display names. Top-level groups are named in a header strip when their tile has room.- tile
Tiling algorithm:
"squarify"(golden-ratio rectangles) or"binary"(balanced binary partition).- padding_inner
Padding between sibling tiles, in pixels.
- color_by
Color leaves by
"parent"(top-level ancestor, categorical) or by"value"(a sequential/diverging ramp).- colormap
Ramp used when
color_by = "value":"viridis","rdbu","ltc"(an earthy teal to sand to rust sequential ramp) or"ltcdiv"(its diverging counterpart, neutral cream at the midpoint). The ramp runs from the smallest leaf value in view to the largest, so a diverging ramp has its midpoint halfway between the two.- label_min_size
Minimum tile side (px) before a label is drawn, at the default font size. It grows with
theme$fontSize.- theme
Optional named list of theme overrides (colors, fonts, ...) merged over the component defaults in the browser.
NULLuses the default theme. Itspaddingentry is the space in px between the edge of the widget and the plot: one number for every side, or numbers namedtop,right,bottomandleftin a list or vector, a side left out keeping the default of 10. Itscategoricalentry is an ordered palette: the colours go to the top- level branches in order, and names on the colours are not matched to them. A colour given as a CSS custom property, such asbackground = "var(--bg)", takes the value the page gives it when the plot draws. After the page changes the property, what the plot drew on a canvas keeps the old colour until it draws again: resize the widget or render it again.- width, height
Widget dimensions (any valid CSS size).
- element_id
Optional explicit DOM id.
Examples
df <- data.frame(
id = c("root", "P1", "P2", "g1", "g2", "g3"),
parent = c(NA, "root", "root", "P1", "P1", "P2"),
value = c(0, 0, 0, 3, 5, 2),
label = c("All", "Pathway 1", "Pathway 2", "Gene 1", "Gene 2", "Gene 3")
)
treemap(df)