How to change colors for each column in the heatmap using "complexheatmap" package?
1
0
Entering edit mode
3.4 years ago
Vasu ▴ 540

Hi,

I have a dataframe "df" like following:

 Sample ID  G1  G2  G3  G4  G5  G6
S1  3       1   1   2   1
S2  2       1   2   1   1
S3  3       2   1   1   1
S4  2   2   1   1   1   1
S5  3       2   1   1   1
S6  2       1   1   2   1
S7  3   3   1   2   1   1
S8  4       2   1   1   1
S9  3       1   2   2   1
S10 2   3   2   2   1   1
S11 2       1   2   4   1
S12 3       2   1   2   1
S13 2       2   1   1   1

I'm using "complexheatmap" R package to generate a heatmap.

plot <- data.frame(df[,-1], row.names=df[,1])

library(ComplexHeatmap)
library(circlize)

pdf("plot.pdf", width=5, height=6.5)
Heatmap(plot, show_row_names = TRUE, show_column_names = TRUE, cluster_rows = FALSE,
        cluster_columns = FALSE,show_column_dend = FALSE,show_row_dend = FALSE) 
dev.off

This gave me a heatmap like - https://imgur.com/a/HMVOH

My Question:

How can I assign different colors for each column. And how to give different legend for each column. I want to give different colors and legend for (3,2,4) in G1 column and different colors and legend for (1,2) in G3 column and different colors and legend for (1,2) in G4 column. And also different Legend headings for different columns.

How to do this?

Thank you

R complexheatmap bioconductor heatmap • 3.1k views
ADD COMMENT
1
Entering edit mode

Hi Bioinfo,

Deleting a question after someone spend time helping you is unnecessary and rude. I have restored this thread.

Wouter

ADD REPLY
0
Entering edit mode
3.4 years ago

That is done by setting the col parameter to Heatmap(). Take a look at my examples:

ADD COMMENT
0
Entering edit mode

No, This is not what I want. I would like to generate a plot showing G1- G6 and each column showing different colors for each values. And the legend needs to be different for each column.

ADD REPLY
0
Entering edit mode

You mean a color bar, like this: C: how to cluster genes in heatmap ?

THe plot that you showed is an Oncoprint, not a Heatmap. Oncoprints can be difficult to generate, but I suggest that you start by looking here: OncoPrint. You can also merge multiple oncoprints together. I recently developed a very complex oncoprint that has 100s of lines of R code.

ADD REPLY
1
Entering edit mode

But without Oncoprint, I got know how to do this.

Heatmap(plot[, 1]) + Heatmap(plot[, 2]) + Heatmap(plot[, 3]) + others...

This way heatmap for each column can be made and different colors for each column can also be given.

ADD REPLY

Login before adding your answer.

Traffic: 1653 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