Does anybody know how to add a color side bar which will be re-ordered by the clustering in pheatmap
1
1
Entering edit mode
10.4 years ago
sw.arker ▴ 70

Hello, I am recently starting to use pheatmap since it can draw more decent heatmap (personal opinion) in comparison with heatmap.2 or heatplot.. however, I want to add a color side bar (on top of the heatmap) as I did in heatmap.2 with different color assigned to each group of sample and re-ordered by the clustering in heatmap. I know in heatmap.2 I can use "ColSideColors", but in pheatmap I could use "annotation"; but I didn't figure out how to get it work, please help!! many thanks!!

the data format like this, and I want the genes under 4 different conditions assigned the same color but re-ordered in heatmap by clustering:

data format: https://www.dropbox.com/s/qc8zjpgcimo71mu/sample.jpg

heatmap R • 17k views
ADD COMMENT
1
Entering edit mode

I do this, but it's not pretty. I use layout() and image() to make my own image plots.

ADD REPLY
0
Entering edit mode

thanks! I will try it!!

ADD REPLY
0
Entering edit mode
ADD REPLY
5
Entering edit mode
6.3 years ago

Use annotation_col, as exemplified here: A: DESeq2 pheatmap returns Error in check.length("fill") : 'gpar' element 'fill' mu

The rownames of your object passed to annotation_col should be the same as the colnames of your object that is being clustered.

A reproducible example:

#Create random data
data <- replicate(20, rnorm(50))
rownames(data) <- paste("Gene", c(1:nrow(data)))
colnames(data) <- paste("Sample", c(1:ncol(data)))

metadata <- data.frame(
      c(rep("case", ncol(data)/2), rep("control", ncol(data)/2)),
      c(rep("cond1", ncol(data)/4), rep("cond2", ncol(data)/4), rep("cond3", ncol(data)/4), rep("cond4", ncol(data)/4)),
      row.names=colnames(data))
colnames(metadata) <- c("casecontrol","condition")
metadata
          casecontrol condition
Sample 1         case     cond1
Sample 2         case     cond1
Sample 3         case     cond1
Sample 4         case     cond1
Sample 5         case     cond1
Sample 6         case     cond2
Sample 7         case     cond2
Sample 8         case     cond2
Sample 9         case     cond2
Sample 10        case     cond2
Sample 11     control     cond3
Sample 12     control     cond3
Sample 13     control     cond3
Sample 14     control     cond3
Sample 15     control     cond3
Sample 16     control     cond4
Sample 17     control     cond4
Sample 18     control     cond4
Sample 19     control     cond4
Sample 20     control     cond4

out <- pheatmap(data, 
      show_rownames=T, cluster_cols=T, cluster_rows=T, scale="row",
      cex=1, clustering_distance_rows="euclidean", cex=1,
      clustering_distance_cols="euclidean", clustering_method="complete", border_color=FALSE,
      annotation_col=metadata)

Screen_Shot_2018_08_16_at_16_55_06

Kevin

ADD COMMENT

Login before adding your answer.

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