makecolors: Make color labels for factors/categorical data.

Description Usage Arguments Details Value Examples

View source: R/makecolors.R

Description

makecolors Generates color labels and legends for factors.

Usage

1
makecolors(object, pal = cbbPalette, keep.order = TRUE)

Arguments

object

A matrix of vector that can be coerced into factors.

pal

A vector of colors.

keep.order

Logical. Keep original order of non-factor strings.

Details

The function accepts either a vector that can be coerced into factors or a matrix where each column is used to generate color labels.

Can also be generate unique pch labels (see Examples).

Value

A list containing:

Legend:

A unique vector/color pair for easy legend plotting.

Colors:

A matrix or vector of colors for plotting.

Examples

1
2
3
4
5
6
7
8
x <- factor(sample(c('a','b','c'), 30, replace = TRUE))
colset <- makecolors(x)
xnum <- jitter(as.numeric(x))
plot(xnum, col = colset$Colors, pch = 16)
legend('topright', legend = names(colset$Legend), col = colset$Legend, pch = 16)

pchset <- makecolors(x, pal = c(16,17,18))$Colors
plot(xnum, col = colset$Colors, pch = pchset)

sean-cho/toolkit documentation built on May 29, 2019, 4:24 p.m.