Set the color mapping of a numerical vector, and the tick and tick labels of its legend
Source:R/utilFuns.R
setColMapAndLegend.RdThe purpose of this function is to auto-handle outliers in the numerical vectors, because outliers compress the color mapping and make it difficult to distinguish among the values of non-outliers.Here are the ways to achieve that goal in this function if outliers are present:
only non-outliers are used in color-value mapping.
a '<' or '>' sign is prefixed to the first or last tick labels.
Usage
setColMapAndLegend(
vec,
colMap = NULL,
whiteValue = NA,
intAsDiscreteCutoff = 6,
rmLegendOutliers = T,
isAnnotation = F,
legendTicks = NULL,
legendTickLabels = NULL
)Arguments
- vec
numerical; a vector or matrix
- colMap
a named numerical vector for the color mapping,
NULL; ifcolMapis not provided, the names ofcolMapis set as the followings: * ifisAnnotation,c('white',x)where x is a random color fromgetDistinctColors. * otherwise,c('green4', 'white', 'red').- whiteValue
Numeric,
NA; it is the value of the white or middle color in the legend ifcolMapconsists of three colors representing, e.g. up, no change, down, etc.- intAsDiscreteCutoff
integer, 6; if
mat1is an integer matrix and has < 6 unique values, the color mapping in the legend will be discrete.- rmLegendOutliers
logical, TRUE; If
colMapis not provided, ifFALSE, the range of legend ticks covers all values ofvacifTRUE, the range of legend ticks covers only non-outliers- isAnnotation
logical,
FALSE; ifTRUE, the legend is for the annotation of a heatmap, not for heatmap itself;- legendTicks
numerical vector, NULL;
- legendTickLabels
character vector, NULL;
Value
a list of following items
colmap: the completedcolMaplegendParas:list(at = legendTicks,labels = legendTickLabels). it may also containslegend_gpifvecis discrete integers; passed toComplexHeatmap::HeatmapAnnotation(annotation_legend_param)newVals: infinite values invec, if present, are set toNAisDiscrete: isvecdiscrete?