myColorRamp5: Creates a Color Gradient for a Numeric Vector

View source: R/base_package_functions.R View source: R/Package-Code5-Compiled.R

myColorRamp5R Documentation

Creates a Color Gradient for a Numeric Vector

Description

Based on a provided numeric vector, returns a color gradient based on quartiles indicating level of expression.

Usage

myColorRamp5(colors, values, percent.mad = 0.5)

Arguments

colors

a character vector of length 5 providing the colors for which the gradient will be based on

values

numeric vector for which the gradient will be based on

percent.mad

percent of the median absolute deviation away from the median value that will determine the binning of the data

Details

The function differs from the standard colorRamp in that the input values are binned before being assigned colors to avoid the heavy influence of extreme values on the color gradient. This function separates the values into quartiles based on the median value of the data and the indicated percent.mad which determines how the upper and lower bins are assigned.

The lowest quartile set from colors[1]-colors[2] ranges from min(values) < x <= median(values) - percent.mad*mad(values)

The lower middle quartile set from colors[2]-colors[3] ranges from median(values) - percent.mad*mad(values) < x <= median(values)

The higher middle quartile set from colors[3]-colors[4] ranges from median(values) < x <= median(values) + percent.mad*mad(values)

The highest quartile set from colors[4]-colors[5] ranges from median(values) + percent.mad*mad(values) < x <= max(values)

(NAs are removed for all calculations)

Value

a vector of color assignments for the values provided (in the same order)

Note

Mostly used internally by plotting functions where points are colored by expression level

Author(s)

~~Alison Moss~~

Examples

##initiate parameters
initiate_params()

##for a given gene of interest, color samples by expression level,
goi <- "Th"
genedat<- RAGP_norm[goi,]
cols <- myColorRamp5(params$expression_gradient.colors,genedat, percent.mad = 0.5)

cols <- myColorRamp5(c("red","orange","yellow","green","blue"),genedat, percent.mad = 0.75)

axm323/dataVisEasy documentation built on Feb. 1, 2024, 11:53 p.m.