2
$\begingroup$

I'm using pheatmap to generate a correlation matrix in R. Ideally, I want my colour scale to run from -1.0 - 1.0 but my lowest negative correlation is 0.6. Is there a way to manually set the range?

color <- makeColorRampPalette(c("navy", "white","white", "red"), 
                             cutoff.distance / max(distmat),100)

   pheatmap(res$r, 
    main = "Correlation Matrix",
    annotation_col = Heat_test, 
    fontsize = 18, 
    color = color, 
    show_rownames = F, 
    show_colnames = F, 
    legend = T)
$\endgroup$

1 Answer 1

1
$\begingroup$

Looking at the pheatmap documentation, it looks like the way to do this is with the breaks argument, which needs to have one more element than the number of defined colours:

breaks

a sequence of numbers that covers the range of values in mat and is one element longer than color vector. Used for mapping values to colors. Useful, if needed to map certain values to certain colors, to certain values. If value is NA then the breaks are calculated automatically. When breaks do not cover the range of values, then any value larger than max(breaks) will have the largest color and any value lower than min(breaks) will get the lowest color.

color.divisions <- 100
color <- makeColorRampPalette(c("navy", "white","white", "red"), 
                             cutoff.distance / max(distmat), color.divisions)

pheatmap(res$r, 
    main = "Correlation Matrix",
    annotation_col = Heat_test, 
    fontsize = 18,
    breaks = seq(-1,1, length.out=(color.divisions + 1)), 
    color = color, 
    show_rownames = F, 
    show_colnames = F, 
    legend = T)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.