Learn R Programming

fifer (version 1.0)

string.to.color: Convert between strings to colors

Description

Automatically convert a vector of strings into a color for easy plotting

Usage

string.to.color(string, colors = NULL)

Arguments

string
a vector of strings representing groups.
colors
a vector of colors, one for each unique element in string.

Value

a vector of colors, one for each element in string

Examples

Run this code
groups = sample(LETTERS[1:5], size=100, replace=TRUE)
plot(rnorm(100), rnorm(100), col=string.to.color(groups))
plot(rnorm(100), rnorm(100), col=string.to.color(groups),
   pch=as.numeric(string.to.color(groups, colors=c(16:20))))

Run the code above in your browser using DataLab