Description Usage Arguments Details Value Author(s) References Examples
View source: R/aveytoolkit_Diverge0.R
Given data and colors, find colors and breaks where the center of the pallete is at 0
1 |
data |
any numeric data type for which a single range can be calculated |
ramp |
the name of an RColorBrewer palette (as character), a character vector of colour names to interpolate, or a colorRampPalette. |
reverse |
logical specifying whether colors should be reversed (e.g. RdBu scale becomes Blue to Red). Default is FALSE. |
maxColors |
the maximum number of colors you wish to interpolate. The number returned will be at most this number. |
Inspired by John Baumgartner's function to diverge a color scale for an image (see reference). I use this function often when making a heatmap and I have a diverging color pallete where I want the middle color (usually white) to map to a zero value. When the distribution is skewed from 0 this doesn't happen by default using pheatmap
(but it does happen automatically for some other heatmap functions like heatmap.2
). This function can be used to get the colors and breaks to pass to the pheatmap
function.
a named list with two elements: breaks and colors
John Baumgartner, Stefan Avey
https://gist.github.com/johnbaums/306e4b7e69c87b1826db
1 2 3 4 5 6 7 8 9 10 11 | ## Not run:
library(pheatmap)
hm <- matrix(rnorm(n = 100, mean = 1, sd = 1), nrow = 10, ncol = 10)
div <- Diverge0(data = hm, ramp = "RdBu", reverse = TRUE)
## In this heatmap, 0 values appear blue which is misleading
pheatmap(mat = hm, rev(brewer.pal(11, "RdBu")))
## In this heatmap, the diverging scale is centered around 0
pheatmap(mat = hm, color = div$colors, breaks = div$breaks)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.