cell_fun_label | R Documentation |
ComplexHeatmap cell function to label heatmap cells
cell_fun_label(
m,
prefix = "",
suffix = "",
cex = 1,
col_hm = NULL,
outline = FALSE,
abbrev = FALSE,
show = NULL,
rot = 0,
sep = "\n",
verbose = FALSE,
...
)
m |
|
prefix , suffix |
|
cex |
|
col_hm |
|
outline |
|
abbrev |
|
verbose |
|
... |
additional arguments are ignored. |
This function serves as a convenient method to add text
labels to each cell in a heatmap produced by
ComplexHeatmap::Heatmap()
, via the argument cell_fun
.
Note that this function requires re-using the specific color
function used for the heatmap in the call to
ComplexHeatmap::Heatmap()
.
This function is slightly unique in that it allows multiple
labels, if m
is supplied as a list
of matrix
objects.
In fact, some matrix
objects may contain character
values with custom labels.
Cell labels are colored based upon the heatmap cell color,
which is passed to jamba::setTextContrastColor()
to determine
whether to use light or dark text color for optimum contrast.
TODO: Option to supply a logical
matrix to define a subset of
cells to label, for example only labels that meet a filter
criteria. Alternatively, the matrix data supplied in m
can
already be filtered.
TODO: Allow some matrix values that contain character
data
to use gridtext
for custom markdown formatting. That process
requires a slightly different method.
Other jam heatmap functions:
heatmap_column_order()
,
heatmap_row_order()
# Examples require ComplexHeatmap Bioconductor/github package
# github:jokergoo/ComplexHeatmap
if (check_pkg_installed("ComplexHeatmap")) {
m <- matrix(rnorm(16)*2, ncol=4)
colnames(m) <- LETTERS[1:4]
rownames(m) <- letters[1:4]
col_hm <- circlize::colorRamp2(breaks=(-2:2) * 2,
colors=c("navy", "dodgerblue", "white", "tomato", "red4"))
# the heatmap can be created in one step
hm <- ComplexHeatmap::Heatmap(m,
col=col_hm,
heatmap_legend_param=list(
color_bar="discrete",
border=TRUE,
at=-4:4),
cell_fun=cell_fun_label(m,
col_hm=col_hm))
ComplexHeatmap::draw(hm)
# the cell label function can be created first
cell_fun <- cell_fun_label(m,
outline=TRUE,
cex=1.5,
col_hm=col_hm)
hm2 <- ComplexHeatmap::Heatmap(m,
col=col_hm,
cell_fun=cell_fun)
ComplexHeatmap::draw(hm2)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.