Numero (version 1.2.0)

nroColorize: Assign colors based on value

Description

Assign colors to map districts based on the respective district values.

Usage

nroColorize(values, ranges = NULL, amplitudes = 1, palette = "rhodo")

Arguments

values

A vector of K values or a K x N data frame, where K is the number of map districts and N is the number of variables.

ranges

A data frame with N rows and 2 columns.

amplitudes

Single value or a vector of N elements or a data frame of N rows that contains the column AMPLITUDE.

palette

One of pre-defined colormap names (see details) or a sorted vector of hexadecimal color codes as strings.

Value

A data frame or a matrix of hexadecimal color codes as strings. If the output is a single column, it is converted to a vector.

If amplitudes = NULL, a data frame that contains the value ranges that would be used for colors is returned.

Details

The argument ranges sets the minimum and maximum district values irrespective of the contents of values. It can be used as a fixed reference across different colorings to ensure that the same value produces the same color across function calls.

The argument amplitudes controls the proportion of the color range that is available for the district value range. For proportions below 1, the minimum district value is assigned to a color that is between the first and middle element in the color palette, and the maximum is assigned to a color that is between the middle and the last element. If amplitude is greater than 1, extreme low and high values are clipped to the first and last color in the palette, respectively.

Available color palettes include "gray", "fire", "jungle", "miami", "rhodo" or "tan". Any other word will revert to a rainbow colormap.

References

Gao S, Mutter S, Casey AE, M<U+00E4>kinen V-P (2018) Numero: a statistical framework to define multivariable subgroups in complex population-based datasets, Int J Epidemiology, https://doi.org/10.1093/ije/dyy113

Examples

Run this code
# NOT RUN {
# Import data.
fname <- system.file("extdata", "finndiane.txt", package = "Numero")
dataset <- read.delim(file = fname)

# Prepare training data.
trvars <- c("CHOL", "HDL2C", "TG", "CREAT", "uALB")
trdata <- scale.default(dataset[,trvars]) 

# K-means clustering.
km <- nroKmeans(data = trdata)

# Self-organizing map.
sm <- nroKohonen(seeds = km)
sm <- nroTrain(som = sm, data = trdata)

# Assign data points into districts.
matches <- nroMatch(centroids = sm, data = trdata)

# District averages for all variables.
planes <- nroAggregate(topology = sm, districts = matches, data = dataset)

# District colors for cholesterol.
chol <- nroColorize(values = planes$CHOL)
print(head(chol))

# District colors for all variables.
colrs <- nroColorize(values = planes)
print(head(colrs))
# }

Run the code above in your browser using DataLab