Description Usage Arguments Value Author(s) Examples
Colored factors permit persistent association of color to a factor, supporting consistent graphical treatment across multiple plots.
1 | colored(x, color.key, ordered = is.ordered(x), default = NA)
|
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
|
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, |
An object of class c('colored',['ordered',]'factor')
David C. Norris
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))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.