vec2col: Generate colors from a vector

Description Usage Arguments Value Author(s) Examples

View source: R/color.R

Description

This functions generates a color vector from an input vector, which can be of the class numeric or factor.

Usage

1
2
3
4
5
6
7
vec2col(vec, n, name)

## Default S3 method:
vec2col(vec, n, name)

## S3 method for class 'factor'
vec2col(vec, n, name)

Arguments

vec

the numeric or factor vector

n

the number of colors to be generated from the palette

name

the name of the palette

Value

a vector of colors corresponding to the input vector

Author(s)

Yihui Xie <https://yihui.org>

Examples

1
2
3
4
5
6
7
8
9
## convert factor to colors
with(iris, plot(Petal.Length, Petal.Width, col = vec2col(Species), pch = 19))

# another palette
with(iris, plot(Petal.Length, Petal.Width, col = vec2col(Species, name = "Dark2"),
    pch = 19))

## turn numeric values to colors
with(iris, plot(Petal.Length, Petal.Width, col = vec2col(Petal.Width), pch = 19))

yihui/MSG documentation built on Aug. 16, 2021, 12:13 p.m.