Learn R Programming

condvis (version 0.2-2)

factor2color: Convert a factor to suitable colors.

Description

Takes a factor and returns a vector of colors representing the factor levels.

Usage

factor2color(x, colors = NULL)

Arguments

x
a factor
colors
colors to use for the levels of x, recycled if too short. Defaults to a qualitative color scheme, "Set3" from RColorBrewer package if available, or rainbow

Value

  • A character vector containing colors.

See Also

cont2color

Examples

Run this code
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