condvis (version 0.5-1)

factor2color: Assign colours to factor vector

Description

This function takes a factor vector and returns suitable colours representing the factor levels. Default is to try to use RColorBrewer for colours, and rainbow otherwise. Can provide custom colours.

Usage

factor2color(x, colors = NULL)

Arguments

x

A factor vector.

colors

The colours to use. Defaults to a qualitative colour scheme; either "Set3" from RColorBrewer if available, or rainbow otherwise.

Value

A character vector of colours.

Details

Uses the RColorBrewer package if installed. Coerces x to factor with a warning.

See Also

cont2color

Examples

Run this code
# NOT RUN {
plot(iris[, c("Petal.Length", "Petal.Width")], pch = 21,
  bg = factor2color(iris$Species))
legend("topleft", legend = levels(iris$Species),
  fill = factor2color(as.factor(levels(iris$Species))))

# }

Run the code above in your browser using DataLab