Question: Conditionally coloring the fold change values to plot a heatmap using pheatmap
gravatar for chetana
21 days ago by
San Diego
chetana40 wrote:

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 bioinformatics • 134 views
ADD COMMENTlink modified 17 days ago • written 21 days ago by chetana40

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

ADD REPLYlink written 20 days ago by Kevin Blighe15k

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.

geneExp <- read.table("ICL004-R_Pattern1-10.txt",
                  header=T, sep="\t")
geneExp_matrix <- as.matrix(geneExp[3:8])
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)
col.pal <- RColorBrewer::brewer.pal(6, "RdBu")
               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 REPLYlink written 17 days ago by chetana40

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 REPLYlink written 17 days ago by Kevin Blighe15k

Please take a look here: Keeping pheatmap colour range the same for different data sets

ADD REPLYlink written 17 days ago by Kevin Blighe15k
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1745 users visited in the last hour