colored: Create a colored factor, an object of class...

Description Usage Arguments Value Author(s) Examples

View source: R/colored.R

Description

Colored factors permit persistent association of color to a factor, supporting consistent graphical treatment across multiple plots.

Usage

1
colored(x, color.key, ordered = is.ordered(x), default = NA)

Arguments

x

A character vector or factor

color.key

A named vector or list mapping factor levels (the names) to colors (the values). If missing (as is likely in initial exploratory analyses), this is generated automatically as a convenience to the user. In case an ordered factor is generated, the order of the levels is determined by the ordering in color.key.

ordered

A logical value stating whether the factor should be ordered

default

An optional argument; when provided, it gives a string in names(color.key) to which all non-matching values of x should be mapped. The effect will be to collect possibly many factor levels under a single key entry. A common choice might be, for example, default='OTHER'.

Value

An object of class c('colored',['ordered',]'factor')

Author(s)

David C. Norris

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# This is an example of de novo construction of a colored factor
weekdays <- colored(c("Mon","Tue","Wed","Thu","Fri"),
                    color.key=c(Mon="blue",Tue="red",Wed="yellow",
                                Thu="purple", Fri="green"))
# This demonstrates how one might use the 'colored' constructor
# to expand the level set of an existing factor.
week <- colored(weekdays,
                color.key=c(Sun="white", key(weekdays), Sat="gray"),
                ordered=TRUE)

# Note that 'droplevels.factor' works fine on colored factors
levels(week)
levels(droplevels(week))

VizOR documentation built on May 30, 2017, 5:29 a.m.