Conditionally coloring the fold change values to plot a heatmap using pheatmap
0
0
Entering edit mode
6.8 years ago
chetana ▴ 60

Hi all,

I'm trying to plot a heat map with fold change (log2 values) values ranging from almost -100 to 100 across 6 time points. There are actually very few points in the extreme ranges of fold change. I was planning on plotting just the -10 to 10 range in the scale with differing color intensity where as the points above or below that will be color coded in a single color. I tried using breaks with (-100,-10,-5,0,5,10,100) but in the legend the color code for -10 to 10 range is not visible. Can you please suggest any other solution. I've been looking for it everywhere but haven't found a solution. I would really appreciate your help. Thanks in advance!

R heatmap • 5.8k views
ADD COMMENT
0
Entering edit mode

Can you paste the exact code that you have been trying via the specification of breaks? - thanks!

ADD REPLY
0
Entering edit mode

Please find the code below. Patterns are the way set of few genes fall into a category based on their expression across the timepoints and I just used it for the row annotation.

library(pheatmap)
library(RColorBrewer)
geneExp <- read.table("ICL004-R_Pattern1-10.txt",
                  header=T, sep="\t")
head(geneExp)
names(geneExp)
geneExp_matrix <- as.matrix(geneExp[3:8])
rownames(geneExp_matrix)<-geneExp$Host.Factor.ID
Patterns<- c(1,2,3,4,5,6,7,8,9,10)
Pattern_color_options<- c(brewer.pal(10, "Set3"))
Pattern_colors <- unlist(lapply(geneExp$Pattern_number,function(x){
 for(P_num in 1:length(Patterns)){
   if(grepl(paste("Pattern_",Patterns[P_num],sep=""),x)) return(Pattern_color_options[P_num])
 }
}))
breaks_heatmap<- c(-100,-10,-5,0,5,10,100)
row_annotation<-data.frame(geneExp$Pattern_number)
rownames(row_annotation)<-geneExp$Host.Factor.ID
col.pal <- RColorBrewer::brewer.pal(6, "RdBu")
pheatmap::pheatmap(geneExp_matrix,
               legend=TRUE,
               cluster_row = FALSE,
               cluster_cols = FALSE, scale = "none",
               breaks = breaks_heatmap,
               annotation_col = NA,
               annotation_row = row_annotation, gaps_row = c(2921, 5685, 7790, 9764, 11407, 13028, 14122, 15053, 15972),
               annotation_legend = TRUE, 
               annotation_names_row = TRUE, annotation_names_col = FALSE,
               show_rownames = FALSE, show_colnames = TRUE,
               legend_breaks = c(-100,-10,-5,0,5,10,100),
               color = col.pal, gaps_col = c(1,2,3,4,5),
               fontsize = 6.5)
ADD REPLY
1
Entering edit mode

Hello chetana my friend, you are specifying the breaks incorrectly.

To specify breaks for a heatmap, you have to do something like this:

breaks <- c(seq(-100, -10, by=5), seq(-9, -5, by=1), seq(-4, 4, by=0.5), seq(5, 9, by=1), seq(10, 100, by=5))
ADD REPLY
0
Entering edit mode
ADD REPLY

Login before adding your answer.

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