Automatic color assignment for annotations on ComplexHeatmap
0
2
Entering edit mode
CodeAway ▴ 60
@codeaway-12991
Last seen 13 months ago

Hello All,

I love the ComplexHeatmap package, and have been using it to make some gene expression heatmaps.  If I wish to add row annotations for genes, with each gene belonging to one of 10 clusters, how do I make automatic color assignments to the groups instead of giving them as a list manually?

I also had a bottom_annotation for the columns, with two classes as follows:

ha_column <- HeatmapAnnotation(df = data.frame(CellType=cellTYPE), col = list(CellType = c("WT" =  "black", "KO" = "green")))

It was easy to assign colors in this case.

But for the rows, I have 10 classes, and then for different data sets, the number of such row classes will change.  So, it will be very helpful if I could get R to assign colors automatically instead of the manual assignments above (black and green).

Any help would be greatly appreciated!

Thanks.

complexheatmap • 2.1k views
0
Entering edit mode

Further to my post above, I tried doing this:

ha_row <- HeatmapAnnotation(df = data.frame(Cluster=top20mrks$cluster), which="row", col = list(Cluster = colorRampPalette(brewer.pal(12,"Paired"))(length(levels(top20mrks$cluster)))) )

But I got the following error:

Error in HeatmapAnnotation(df = data.frame(Cluster = top20mrks$cluster), : elements in col should be named vectors. So, how can I make this a named vector? Thanks! ADD REPLY 1 Entering edit mode I solved this myself as follows: ttxx <- colorRampPalette(brewer.pal(12,"Paired"))(length(levels(top20mrks$cluster)))
names(ttxx) <- levels(top20mrks$cluster) ha_row <- HeatmapAnnotation(df = data.frame(Cluster=top20mrks$cluster), which="row", col = list(Cluster = ttxx))

Now it works.