Annotation of Complex Heatmap
0
1
Entering edit mode
3 months ago
abiuma ▴ 30

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 • 489 views
ADD COMMENT
2
Entering edit mode

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
ADD REPLY
2
Entering edit mode

Alternatively, have you looked at options for adding a custom legend? See https://jokergoo.github.io/ComplexHeatmap-reference/book/legends.html#add-customized-legends

ADD REPLY
1
Entering edit mode

Thanks..I got it to work now.

ADD REPLY
1
Entering edit mode

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

ADD REPLY
2
Entering edit mode

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

ADD REPLY

Login before adding your answer.

Traffic: 1737 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6