jokergoo / ComplexHeatmap

Make Complex Heatmaps
https://jokergoo.github.io/ComplexHeatmap-reference/book/
Other
1.31k stars 227 forks source link

Combine heatmap with another plot based on expression for interpretation #1221

Open Motoufiq opened 1 week ago

Motoufiq commented 1 week ago

Hi,

We are examining a set of 30 genes that exhibit differential expression in response to infection. I have created a heatmap using the ComplexHeatmap package, based on whole number scores ranging from 0 to 10 from an independent experiment (where 0 indicates no association and 10 indicates the strongest association). Please refer to the R code below:

I have another dataset includes gene expression values (log2 fold change) for multiple donors at different time points (1hr, 10hr, 48hr) post-infection. The matrix consists of 30 genes as rows and 20 columns (time points).

To enhance interpretation, it would be useful to indicate the directionality of regulation (up or down) for each gene. I am interested in combining the heatmap with an additional plot, such as a line plot, bar plot, or boxplot, adjacent to it. Any suggestions to facilitate interpretation would be appreciated.


library(circlize)

# Define the custom function to add text to each cell without decimal points
cell_fun <- function(j, i, x, y, width, height, fill) {
  grid.text(sprintf("%d", round(Scores[i, j])), x, y, gp = gpar(fontsize = 15))
}

# Create the column annotation
column_ha <- HeatmapAnnotation(df = data.frame(Type = Column_anno$Type),
                               show_annotation_name = F,
                               col = list(Type = c("Pathobiology" = "darkblue", "Functional KO" = "magenta")),
                               simple_anno_size = unit(2.0, "cm"))

# Plot heatmap
pdf("Heatmap_Scores.pdf", height = 15, width = 20)
Heatmap(Scores, 
        name = "Scores (/10)", 
        col = colorRamp2(c(0, 5, 10), c("white", "green", "red")),
        heatmap_legend_param = list(at = seq(0, 10, by=2), color_bar = "continuous"),
        na_col = "grey",
        cluster_rows = TRUE,
        cluster_columns = F,
        top_annotation = column_ha,
        row_names_max_width = unit(10, "in"),
        row_title_gp = gpar(fontsize = 15),
        column_title_gp = gpar(fontsize = 15),
        column_names_gp = gpar(fontsize = 12),
        column_names_rot = 45,
        row_names_gp = gpar(fontsize = 15),
        show_column_names = TRUE,
        column_names_side = "top",
        cell_fun = cell_fun)
dev.off()```