Set the color mapping of a numerical vector, and the tick and tick labels of its legend
Source:R/utilFuns.R
setColMapAndLegend.Rd
The 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
; ifcolMap
is not provided, the names ofcolMap
is 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 ifcolMap
consists of three colors representing, e.g. up, no change, down, etc.- intAsDiscreteCutoff
integer, 6; if
mat1
is an integer matrix and has < 6 unique values, the color mapping in the legend will be discrete.- rmLegendOutliers
logical, TRUE; If
colMap
is not provided, ifFALSE
, the range of legend ticks covers all values ofvac
ifTRUE
, 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 completedcolMap
legendParas
:list(at = legendTicks,labels = legendTickLabels)
. it may also containslegend_gp
ifvec
is discrete integers; passed toComplexHeatmap::HeatmapAnnotation(annotation_legend_param)
newVals
: infinite values invec
, if present, are set toNA
isDiscrete
: isvec
discrete?