This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Annotation of Complex Heatmap

Hi,

I would like add this metadata to my heatmap. I have a couple of issues 1) I am not able to assign the colours I want 2) How do I get all the celltypes under one legend. Currently with this command I get 2 different legends for each cell type. Could some one help me.

This is my Metadata:

IDs  celltype1  celltype2
ID1     Cells_1    
ID2     Cells_1    Cells_2
ID3     Cells_1    Cells_2
ID4                     Cells_2
ID5     Cells_1    
ID6     Cells_1    Cells_2

This is my code

ann_P_Merge <- data.frame(Metadata$celltype1, Metadata$celltype2 )

colnames(ann_P_Merge) <- c('celltype1', 'celltype2 ')

type_colors <- list('Celltypes' = c('celltype1' = 'royalblue', 'celltype2 ' = 'magenta'))

colAnn_P_Merge <- HeatmapAnnotation(
  df = ann_P_Merge,
  which = 'col',
  col = type_colors ,
  annotation_width = unit(c(1, 4), 'cm'),
  gap = unit(1, 'mm'), gp = gpar(col = "black", fontsize = 25)
)

ht1 = Heatmap((t(df4)), name = "Test", col = col_fun, rect_gp = gpar(col = "black", lwd = 0.5), cluster_columns = FALSE, cluster_rows = TRUE,
              top_annotation= colAnn_P_Merge, row_names_gp = gpar(fontsize = 10, "fontface" = "bold"), 
              column_names_gp = gpar(fontsize = 10))
complexheatmap

How do I get all the celltypes under one legend.

You have two columns of metadata which is why you get two legends.

To get a single legend you would need to combine the labels across celltype1 and celltype2, e.g.,

IDs celltype1 celltype2 Single Label
ID1 Cells_1 Cells_1
ID2 Cells_1 Cells_2 Cells_1&2
ID3 Cells_1 Cells_2 Cells_1&2
ID4 Cells_2 Cells_2

Thanks! Then how would the heatmap look? The compleas heatmap tutorial only shows 2 different bars that we can give for the metadata. It does not show we can do 2 different metadat in one bar. If I am to make a bar with the Single Label column, would the complex heatmap divide the colored boxes and make into 2?..

This is the example complex heatmap provides. Here it shows 2 annotations foo and bar in different rows.

enter image description here

you can add as many annotations as you want, there's no limit to just 2.

Thanks..I got it to work now.

0 answers

No answers yet.

Log in to answer this question.