6.3 Heatmap Annotation

To annotate columns and rows of the heatmap, we use the anno_column and anno_row arguments, respectively. anno_column takes a vector of one or more strings that correspond to the names of columns in pData, and anno_row takes a vector of one or more strings that correspond to the names of column in fData. By default, MSnSet.utils::jet2.colors is used for character, factor, and logical values, and circlize::colorRamp2 with a viridis color palette is used for numeric values.

When annotating sample correlation heatmaps, only anno_column may be specified. Similarly, when annotating feature correlation heatmaps, only anno_row may be specified. Row or column annotations will be included along the other axis.

We will annotate the rows using values in the "isSpike" (logical) column of fData(m) and annotate rows using the values in the "Type" (factor) and "Age" (numeric) columns of pData(m).

# Expression heatmap with row and column annotation
complex_heatmap(m, anno_row = "isSpike", anno_column = c("Type", "Age"))

6.3.1 Modifying Default Colors

We can change the colors of row and column annotations by passing lists to anno_row_colors and anno_column_colors, respectively. For example, we will change the colors of "Type" so that “Control” is a different shade of blue (“#414DBE”) and “Case” is a dark yellow (#BEB241). We will also change the colors of "Age" so that the minimum value is white and the maximum value is dark red. Since age is a numeric column, we must use circlize:colorRamp2.

Tip: Use palettes from the RColorBrewer package, an interactive color wheel (like this one from canva), or a color palette generator (like this one also from canva) to find colors.

# Modify colors for Type and Age
complex_heatmap(m, anno_column = c("Type", "Age"),
                anno_column_colors = list(
                  Type = c("#414DBE", "#BEB241"),
                  Age = circlize::colorRamp2(
                    breaks = range(m$Age, na.rm = TRUE),
                    colors = c("white", "darkred"))
                ))