Plot a subtype‑specific gene expression heatmap
Source:R/plot_subtype_heatmap.R
plot_subtype_heatmap.RdDraws a heatmap of curated subtype‑driver genes using the output of
classifyHNSC. The function scales expression values per gene
and annotates samples by their predicted molecular subtype.
Usage
plot_subtype_heatmap(
expr,
subtype,
idType = c("SYMBOL", "ENSEMBL", "ENTREZID", "REFSEQ"),
gene_set = NULL,
main = "Subtype heatmap",
show_rownames = TRUE,
cluster_rows = FALSE,
cluster_cols = FALSE,
cap = NULL,
color = NULL,
low_color = "#2c7bb6",
mid_color = "white",
high_color = "#d7191c",
n_color = 100,
silent = FALSE,
...
)Arguments
- expr
A numeric gene expression matrix with genes in rows and samples in columns. Row names must be gene symbols (default) or identifiers matching
idType. Column names must be sample IDs.- subtype
A named factor vector giving the predicted subtype for each sample (e.g.
c(sample1 = "Basal", sample2 = "Classical")). This is the direct output ofclassifyHNSC(..., outputType = "class"). A two‑column data frame with columnsSampleandSubtypeis also accepted for convenience, but will be coerced to a named vector. Probability matrices are not allowed.- idType
Character string specifying the gene identifier type used in the rownames of
expr. Acceptable values are"SYMBOL"(default),"ENSEMBL","ENTREZID", or"REFSEQ". Non‑symbol identifiers are automatically converted to gene symbols.- gene_set
A named list of genes to display, where names correspond to the subtype levels. The default uses a built‑in curated set of known HNSCC subtype markers.
- main
Title for the heatmap.
- show_rownames
Logical, whether to show gene names (default
TRUE).- cluster_rows
Logical, whether to cluster rows (default
FALSE).- cluster_cols
Logical, whether to cluster columns (default
FALSE).- cap
Numeric value at which to cap (trim) the scaled expression values. Values above
capare set tocap, values below-capare set to-cap. Default isNULL(no capping). Typical choices are2or3, but the appropriate threshold depends on the data distribution.- color
A character vector of colours to use for the heatmap gradient. If
NULL(default), a three‑colour gradient is built fromlow_color,mid_colorandhigh_colorwithn_colorlevels. If supplied, this vector is passed directly topheatmapand thelow_/mid_/high_arguments are ignored.- low_color, mid_color, high_color
Colours for the gradient when
color = NULL.low_colorandhigh_colormap to the minimum and maximum scaled values, whilemid_colorcorresponds to zero. Defaults are"#2c7bb6"(blue),"white", and"#d7191c"(red), respectively.- n_color
Number of colour levels to generate in the gradient (default 100). Only used when
color = NULL.- silent
Logical. If
FALSE(default), the heatmap is drawn directly to the current graphics device. IfTRUE, the heatmap is built but not drawn, returning a gtable object for manual drawing withgrid::grid.draw().- ...
Additional arguments passed to
pheatmap. Note thatcoloris set internally and should not be passed via....
Examples
if (FALSE) { # \dontrun{
# Directly from classifyHNSC output
subtypes <- classifyHNSC(TCGA_LUSC, outputType = "class")
plot_subtype_heatmap(TCGA_LUSC, subtypes)
# With custom capping and colours
plot_subtype_heatmap(TCGA_LUSC, subtypes,
cap = 2,
low_color = "green", high_color = "red")
} # }