factor2color {condvis}R Documentation

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.

Details

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

Value

A character vector of colours.

See Also

cont2color

Examples

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))))


[Package condvis version 0.5-1 Index]