get.colvector.Rd
Given a vector of class labels, return a color vector corresponding to the 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.
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
.
A list, with following elements -
labels
key : a matrix, a 2 x unique class labels
character matrix showing how values in labels
have mapped to col
#> x #> a b c d #> 3 7 8 2#> $labels.col #> [1] "green" "green" "green" "blue" "green" "blue" "blue" "blue" #> [9] "green" "red" "orange" "blue" "blue" "red" "blue" "green" #> [17] "orange" "red" "green" "green" #> #> $key #> [,1] [,2] [,3] [,4] #> "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" "green" "green" "grey" "grey" "blue" "blue" "blue" #> [9] "green" "red" "orange" "blue" "blue" "red" "blue" "green" #> [17] "orange" "red" "green" "green" #> #> $key #> [,1] [,2] [,3] [,4] [,5] #> "a" "b" "c" "d" NA #> col "red" "blue" "green" "orange" "grey" #>