Skip to contents

Convert a matrix made of numbers into a hexadecimal matrix for rgb colorization.

Usage

mat_num2color(
  mat1,
  mat.hsv.h = TRUE,
  notch = 1,
  s = 1,
  v = 1,
  forced.color = NULL,
  safer_check = TRUE
)

Arguments

mat1

Matrix 1 of non negative numerical values that has to be colored (matrix class). NA allowed.

mat.hsv.h

Single logical value. Is mat1 the h of hsv colors ? (if TRUE, mat1 must be between zero and 1). If FALSE, mat1 must be made of positive integer values without 0.

notch

Single value between 0 and 1 to shift the successive colors on the hsv circle by + notch.

s

S argument of hsv(). Single numeric value between 0 and 1.

v

V argument of hsv(). Single numeric value between 0 and 1.

forced.color

Must be NULL or hexadecimal color code or name given by colors(). The first minimal values of mat1 will be these colors. All the color of mat1 can be forced using this argument.

safer_check

Single logical value. Perform some "safer" checks (see https://github.com/safer-r)? If TRUE, checkings are performed before main code running: 1) R classical operators (like "<-") not overwritten by another package because of the R scope and 2) required functions and related packages effectively present in local R lybraries. Set to FALSE if this fonction is used inside another "safer" function to avoid pointless multiple checkings.

Value

A list containing:

- $mat1.name: name of mat1

- $colored.mat: colors of mat1 in hexa

- $problem: logical. Is any colors of forced.color overlap the colors designed by the function. NULL if forced.color = NULL

- $text.problem: text when overlapping colors. NULL if forced.color = NULL or problem == FALSE

Author

Gael Millot <gael.millot@pasteur.fr>

Yushi Han <yushi.han2000@gmail.com>

Haiding Wang <wanghaiding442@gmail.com>

Examples

mat1 = matrix(c(1,1,1,2,1,5,9,NA), ncol = 2) ; 
dimnames(mat1) <- list(LETTERS[1:4], letters[1:2]) ; 
mat_num2color(mat1, mat.hsv.h = FALSE, notch = 1, s = 1, v = 1, forced.color = NULL)
#> $mat1.name
#> [1] "mat1"
#> 
#> $colored.mat
#>   a         b        
#> A "#FFAA00" "#FFAA00"
#> B "#FFAA00" "#00AAFF"
#> C "#FFAA00" "#FF0000"
#> D "#AAFF00" NA       
#> 
#> $problem
#> NULL
#> 
#> $text.problem
#> NULL
#>