Description Usage Arguments Details Value Author(s) Examples
Given a vector of class labels, return a color vector correponding to the unique class values. There is an option to set a different color for NA
. A vector with corresponding color values and a key specifying color value of each class label is returned.
1 | get.colvector(labels,col, NA.flag=FALSE, NA.col="grey")
|
labels |
vector, labels for which color vector is desired. Can be |
col |
vector, a character vector containing colors for each unique class label. Also accepts colors from |
NA.flag |
logical, a logical flag where |
NA.col |
character, color value specifying how |
if the vector labels
has names
, the returned color coded vector will also have names
.
labels.list |
A list, with following elements - |
labels.col
: character, a color coded character vector of labels
key
: matrix, a character matrix showing how values in labels
have mapped to col
Arshi Arora
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | set.seed(123)
x<-sample(letters[1:4], 20, replace=TRUE)
#table(x)
#x
#a b c d
#4 5 4 7
x.col<-get.colvector(x,c("red","blue","green","orange"))
#x.col$labels.col
#[1] "blue" "orange" "blue" "orange" "orange" "red" "green" "orange"
#[9] "green" "blue" "orange" "blue" "green" "green" "red" "orange"
#[17] "red" "red" "blue" "orange"
#x.col$key
#[,1] [,2] [,3] [,4]
#ul "a" "b" "c" "d"
#col "red" "blue" "green" "orange"
#lets add some NAs
x[c(1,4,5)] = NA
#
x.col<-get.colvector(x,c("red","blue","green","orange"), NA.flag=TRUE, NA.col="grey")
# x.col$labels.col
#[1] "grey" "orange" "blue" "grey" "grey" "red" "green" "orange"
#[9] "green" "blue" "orange" "blue" "green" "green" "red" "orange"
#[17] "red" "red" "blue" "orange"
#x.col$key
#[,1] [,2] [,3] [,4] [,5]
#ul "a" "b" "c" "d" "NA"
#col "red" "blue" "green" "orange" "grey"
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.