Hi,
I've got fold change data for samples 1 and 2 from time point t1 to time point t2. I want to create a heat map using pheatmap for subsets of genes (~50-100 per set) but I want to be able to define the colour scale to be the same for all.
At the moment, R picks the range based on the highest fold change e.g.
Heat map 1: this subset has a 200 fold upregulation but no downregulation so 0 is blue and +200 is red.
Heat map 2: this subset has 100 fold down regulation in one gene and only 2 fold upregulation for another, so the range will be -100 is blue and +2 is red.
Is there a way that I can say +200 is always red and -100 is always blue and keep this range for all heat maps?
Thanks.
1 answer
This is sample code for the ALL dataset I downloaded from Bioconductor:
library(ALL)
library(pheatmap)
library(RColorBrewer)
# Imports the sample expression data
data("ALL")
expressionData = exprs(ALL)
# Sets the minimum (0), the maximum (15), and the increasing steps (+1) for the color scale
# Note: if some of your genes are outside of this range, they will appear white on the heatmap
breaksList = seq(0, 15, by = 1)
# Plots the first heatmap
pheatmap(expressionData[1:10, ], # Plots the first 10 genes of the dataset
color = colorRampPalette(rev(brewer.pal(n = 7, name = "RdYlBu")))(length(breaksList)), # Defines the vector of colors for the legend (it has to be of the same lenght of breaksList)
breaks = breaksList) # Sets the breaks of the color scale as in breaksList
# Plots the second heatmap with the same color and breaks options
pheatmap(expressionData[20:30, ], # Plots the third 10 genes of the dataset
color = colorRampPalette(rev(brewer.pal(n = 7, name = "RdYlBu")))(length(breaksList)),
breaks = breaksList)
First heatmap
Second heatmap
Log in to answer this question.
From the manual: https://cran.r-project.org/web/packages/pheatmap/pheatmap.pdf, I think you can use the breaks option.