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
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:
00
NA
and other non-numbers are preserved as in the original inputThe 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
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:
col
maxval
NA
and other non-numbers are preserved bgcol
. This behavior can also be turned off by
setting bgcol
to NULL
. The function also works on matrices
y x2col(y, maxval=3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.