This vignette demonstrates functions in the colors range.

library(shrt)

It will be handy to have a vector and a matrix with numbers

x = c(-0.2, 0, 0.04, 0.5, 1, NA, 1.2, 0.8)
names(x) = letters[1:length(x)]
x
y = mtrx(seq(-4, 4, length=9), row.names=letters[1:3], col.names=LETTERS[1:3])
y[1,3] = NA
y[2,3] = Inf
y

x2hex

x2hex converts numbers in a [0,1] range into hexadecimal strings that can be used as transparency values

x
x2hex(x)

The function provides useful behavior in special cases:

The function also works when the input is a matrix.

xmat = matrix(x, ncol=2)
colnames(xmat) = LETTERS[1:2]
rownames(xmat) = letters[1:4]
xmat
x2hex(xmat)

Note the column and row names are preserved under the transformation.

x2col

x2col converts numbers into colors on a two-color scale. Intermediate colors are created using transparency codes.

x
x2col(x)

The function provides the following behavior:

The function also works on matrices

y
x2col(y, maxval=3)


tkonopka/shrt documentation built on March 5, 2020, 2:51 p.m.