asCol {easylegend}R Documentation

Converts categorical values to colors. Wrapper for setFactorGraphics.

Description

Converts categorical values to colors. Wrapper for setFactorGraphics.

Usage

asCol(x, export = FALSE, ...)

Arguments

x

A vector of numerical, character, boolean or factor values, representing categories (non-continuous, with a limited number of unique values).

export

Single logical value. If TRUE, the result of setFactorGraphics will be saved into the output attribute fg.

...

Additional parameters passed to setFactorGraphics.

Value

Returns a list of colors, with attributes fg set to output of setFactorGraphics.

Examples

library( "easylegend" ) 


# Example: x numerical values, points =======================
x <- sample( x = round(rnorm(10),2), size = 20, replace = TRUE )

asCol( x ) 
##  [1] "#CB4D42" "#D62A9C" "#009979" "#6D8200" "#B640D5" "#A86C00" "#A86C00"
##  [8] "#6D8200" "#B640D5" "#009979" "#B640D5" "#0093BC" "#A86C00" "#0093BC"
## [15] "#1D75E1" "#D62A9C" "#009100" "#A86C00" "#A86C00" "#A86C00"
asCol( x, export = TRUE ) 
##  [1] "#CB4D42" "#D62A9C" "#009979" "#6D8200" "#B640D5" "#A86C00" "#A86C00"
##  [8] "#6D8200" "#B640D5" "#009979" "#B640D5" "#0093BC" "#A86C00" "#0093BC"
## [15] "#1D75E1" "#D62A9C" "#009100" "#A86C00" "#A86C00" "#A86C00"
## attr(,"factorGraphics")
## $legend
## function (x, y = NULL, legend = c("-2.35", "-1.07", "-0.6", "-0.51", 
## "-0.22", "0.09", "0.4", "0.68", "1.87"), col = c("#CB4D42", "#A86C00", 
## "#6D8200", "#009100", "#009979", "#0093BC", "#1D75E1", "#B640D5", 
## "#D62A9C"), pch = NULL, fill = NULL, ...) 
## {
##     arguments <- list(x = x, y = y, legend = legend)
##     if (!is.null(col)) {
##         arguments <- c(arguments, list(col = col))
##     }
##     if (!is.null(fill)) {
##         arguments <- c(arguments, list(fill = fill))
##     }
##     if (!is.null(pch)) {
##         arguments <- c(arguments, list(pch = pch))
##     }
##     arguments <- c(arguments, list(...))
##     do.call(what = get("legend", pos = "package:graphics"), args = arguments)
##     return(invisible(arguments))
## }
## <environment: 0x079b5384>
## 
## $col
## function (x) 
## {
##     x <- data.frame(values = x, id = 1:length(x), stringsAsFactors = FALSE)
##     x <- merge(x = x, y = convert, by = "values", all.x = TRUE, 
##         sort = FALSE)
##     x <- x[order(x[, "id"]), ]
##     if (any(is.na(x[, "col"]))) {
##         warning("Some values in 'x' are new. Color set to NA")
##     }
##     return(as.character(x[, "col"]))
## }
## <environment: 0x079aa48c>
## 
## $iCol
## [1] "#CB4D42" "#A86C00" "#6D8200" "#009100" "#009979" "#0093BC" "#1D75E1"
## [8] "#B640D5" "#D62A9C"
## 
## $iBreaks
##  [1] -2.990 -1.710 -0.835 -0.555 -0.365 -0.065  0.245  0.540  1.275  2.465
## 
## attr(,"class")
## [1] "factorGraphics"

[Package easylegend version 1.2.4 Index]