Convert numeric matrix to heatmap colors
Usage
matrix2heatColors(
x,
colorV = group2colors(colnames(x)),
defaultBaseColor = "#FFFFFF",
transformFunc = c,
lens = 0,
shareLimit = TRUE,
numLimitFactor = 0.95,
numLimit = NULL,
baseline = 0,
color_below_baseline = "#FFFFFF",
divergent = FALSE,
rampN = 15,
trimRamp = c(0, 0),
verbose = FALSE,
...
)Arguments
- x
numericmatrix. If there are nocolnames(x)they will be created usingjamba::makeNames(rep("x", ncol(x))).- colorV
charactervector of R colors, named bycolnames(x), and recycled toncol(x)if needed. IfcolorVis supplied as a list, the list elements are mapped tocolnames(x)in order.- defaultBaseColor
charactervector of R colors used as the default base color, whencolorVis supplied as a vector.- transformFunc
functionapplied to numeric values before the color gradient is mapped to numeric values. For example,transformFunc=function(i)-log10(i)would map colors to P-value using a-log10(p)transformation.- lens
numericvalue passed tojamba::warpRamp()to adjust the distribution of colors along the numeric range.logicalindicating whether one numeric limitnumLimitshould be used to define the numeric range for color mapping.- numLimitFactor
numericwhennumLimitis NULL, this factor is applied to the maximum numeric value to determine thenumLimit.- numLimit
numericvalue to define the maximum numeric value above which all numeric values are mapped to the maximum color. When set toNULLthenumLimitFactoris used to define thenumLimit.- baseline
numericvalue to define the numeric baseline, used whendivergent=FALSE. Values are recycled toncol(x)to be applied to each column individually.- color_below_baseline
charactercolor used when numeric value is below thebaseline. Values are recycled toncol(x)to be applied to each column individually. Whencolor_below_baselineisNULL, the first color in the color ramp is used for all values below the baseline.- divergent
logicalindicating whether to apply colors to the numeric range symmetric around zero.- rampN
integervalue to define the number of color breaks for each color gradient.- trimRamp
numericvector with two values, used byjamba::getColorRamp()to trim the intermediate color gradient before creating the final color ramp with lengthrampN. For example, by defaultjamba::getColorRamp()creates a color gradient with 15 colorr, defined by argumentgradientN=15, so the argumenttrimRamp=c(4,2)will trim the first 4 colors and the last 2 colors from the 15-color gradient, before generating the final color gradient with lengthrampN. ThetrimRampargument is especially useful to remove the leading white color, or to trim the first few colors to ensure the first color in the gradient is visibly different from the background color defined bydefaultBaseColor.- verbose
logicalindicating whether to print verbose output.- ...
additional arguments are passed to
jamba::getColorRamp()for additional customization. These arguments are handled across all columns, and not a column-by-column basis.
Details
This function is intended as a rapid way of applying a color
gradient to columns of numeric values, where each column
has its own base color. It calls jamba::getColorRamp()
for each column, and when supplied with one color, it
creates a color gradient from "grey95" to the output
of jamba::color2gradient().
When lens is non-zero, the color gradient is warped in order
to intensify the color saturation across the numeric range.
See also
Other colorjam assignment:
col_div_xf(),
col_linear_xf(),
group2colors(),
rainbowJamMulti(),
vals2colorLevels(),
vibrant_color_by_hue()
Examples
set.seed(123);
# generate a random numeric matrix
m1 <- matrix(ncol=12, rnorm(120));
m1n <- m1;
m1n[] <- format(round(abs(m1), digits=2), trim=TRUE);
jamba::imageByColors(
matrix2heatColors(abs(m1),
transformFunc=c,
divergent=FALSE,
lens=-5,
shareNumLimit=TRUE,
baseline=0,
numLimit=4),
cellnote=m1n);