data_colors | R Documentation |
Given a matrix of observation/element rows and variable/measurement columns, compute a color for each row (or group of rows) such that the colors are distinct, and where more-similar colors roughly designate more-similar data rows (or groups of rows).
data_colors( data, run_umap = TRUE, groups = NULL, minimal_saturation = 33, minimal_lightness = 20, maximal_lightness = 80 )
data |
A matrix whose rows represent elements/observations and columns represent variables/measurements. |
run_umap |
A boolean specifying whether to run UMAP on the data to convert it to 3D (by default,
|
groups |
An optional array with an entry per row containing the identifier of the group the row belongs to. |
minimal_saturation |
Exclude colors whose saturation ( |
minimal_lightness |
Exclude colors whose lightnes ( |
maximal_lightness |
Exclude colors whose lightnes ( |
This is intended to provide a "reasonable" set of colors to "arbitrary" data, for use as a convenient default when investigating unknown data sets. It is not meant to replace hand-picked colors tailored for specific data (e.g. using red colors for "bad" rows and green colors for "good" rows).
This ensures all colors are distinct by packing the (visible part) of the CIELAB color space with the needed number of spheres. To assign the colors to the data, it uses UMAP to reduce the data to 3D. It then uses principal component analysis to represent both the chosen colors (3D sphere centers) and the (3D UMAP) data as point clouds with coordinates in the range 0-1, and finally uses a stable matching algorithm to map these point clouds to each other, thereby assigning a color to each data row. If the data is grouped, then the center of gravity of each group is used to generate a color for each group.
An array with one entry per row, whose names are the matrix rownames
, containing the
color of each row. If groups
was specified, the array will contain one entry per
unique group identifier, whose names are the as.character
group identifiers,
containing the color of each group.
chameleon::data_colors(stackloss)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.