how to pheatmap color bar based on column category
1
1
Entering edit mode
2.6 years ago
Bioinfonext ▴ 460

Hi all,

For plotting heatmap, I used pheatmap just by taking numerical values but not sure how to annotate and to divide heatmap based on column category.

Code which I used just taking numeral value;

x <- read.table("pheatmap.txt",sep="\t",head=T,row.names=1,check.names=F)
library('pheatmap')
pdf("16s.pdf", height=20,width=13)
pheatmap(x,scale="row",color =colorRampPalette(c('blue','yellow'))(12),cluster_cols =F,show_colnames = T,cluster_row=T,border_color="NA", fontsize_row=10,fontsize =10)
dev.off();

Now Could you please help how should I take only numerical value from the below file for pheatmap and then how to divide the plot into three different category; leaf, root, soil, and then want to add a color bar on top based on season?

Season          dry  dry    wet wet dry dry wet wet dry dry wet wet
Compartment Leaf    Leaf    Leaf    Leaf    Root    Root    Root    Root    Soil    Soil    Soil    Soil
Burkholderiaceae0   0   0   0.103   0.244   0.001   0.143   0.08    0.032   0.01    0.01    0.032
Bradyrhizobium  0   0   0   0   0.1354  0.094   0.12    0.16    0.211   0.005   0.00744 0.006
Anaeromyxobacter0.04    0   0   0   0.0874  0.139   0.058   0.07    0.11    0.06    0.026   0.034
Geobacter   0.001   0.0004  0   0   0.01    0.016   0.0146  0.08    0.016   0.05    0.0283  0.02
Microbacterium  0.31    0   0.02    0.038   0.003   0.03    0.0038  0.0 0   0.002   0.008   0.002
Rhizobiales 0   0   0   0   0.008   0.001   0.011   0.01    0.0121  0.01    0.4 0.0164

I would like to get image like this and also shown in this publication Fig1 (https://www.nature.com/articles/s41396-021-00974-2); instead of soil type I want to have Compartment; leaf, root, soil and then season (wet/dry) at the top

Many thanks,

Bioconducter R pheatmap • 3.1k views
ADD COMMENT
3
Entering edit mode
2.6 years ago
Chris Dean ▴ 410

I would approach this problem in the following way: first, convert the column names in your count matrix to sample names; second, generate a second data.frame with the factors you want to divide the plot by. Then, you can use the annotation_col parameter to divide the plot in the way you want.

A simplified example of this is shown below:

matrix <- structure(list(S1 = c(0, 0, 0.04, 0.001, 0.31, 0), S2 = c(0, 0, 0, 4e-04, 0, 0), S3 = c(0, 0, 0, 0, 0.02, 0), S4 = c(0.103, 0, 0, 0, 0.038, 0), S5 = c(0.244, 0.1354, 0.0874, 0.01, 0.003, 0.008), S6 = c(0.001, 0.094, 0.139, 0.016, 0.03, 0.001)), class = "data.frame", row.names = c("OTU1", "OTU2", "OTU3", "OTU4", "OTU5", "OTU6"))

environment <- structure(list(category = structure(c(1L, 1L, 3L, 3L, 2L, 2L), .Label = c("Leaf", "Root", "Soil"), class = "factor"), season = structure(c(1L, 1L, 1L, 2L, 2L, 1L), .Label = c("dry", "wet"), class = "factor")), class = "data.frame", row.names = c("S1", "S2", "S3", "S4", "S5", "S6"))

pheatmap(matrix, annotation_col = environment, cluster_rows = TRUE, cluster_cols = FALSE, show_colnames = TRUE, cluster_distance_rows = "euclidean", clustering_method = "complete", fontsize = 10, fontsize_row = 10)

Heatmap

ADD COMMENT

Login before adding your answer.

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