0

I am new to R and started using pheatmap to visualize log2 fold changes in gene expression in treated vs control cells. By default, pheatmap sets the upper limit of the color key to 6 and the lower limit to -2. Is there a way to assign the colors in a way that all values above 4 are assigned to the maximum intensity of red, values below -1 are assigned to the maximum intensity of blue and values in between are assigned to colors of varying intensity?

This is the code I have been using:

pheatmap(my_matrix,cluster_cols = FALSE,cellwidth = 30,fontsize = 7,height = 40,show_rownames = FALSE)

I would like to use as colors:

colorRampPalette(rev(brewer.pal(n=7,name="RdYlBu")))
DP_LMU
  • 1
  • 1
  • 1
  • I have tried using the "breaks" argument. However, values that are out of the specified range show up as white instead of either red or blue – DP_LMU May 04 '17 at 21:41

1 Answers1

-2
colors<-colorRampPalette(rev(brewer.pal(n=7,name="RdYlBu")))(255)
pheatmap(my_matrix,cluster_cols = FALSE,cellwidth = 30,fontsize = 7,height = 40,show_rownames = FALSE, col=colors)
  • 2
    Welcome to Stack Overflow! Thank you for this code snippet, which may provide some immediate help. A proper explanation [would greatly improve](//meta.stackexchange.com/q/114762) its educational value by showing *why* this is a good solution to the problem, and would make it more useful to future readers with similar, but not identical, questions. Please [edit] your answer to add explanation, and give an indication of what limitations and assumptions apply. – Toby Speight Jun 01 '17 at 12:22