brewPalFac: Brew a color palette from a factor x with optional names.

Description Usage Arguments Value Implementation

Description

Uses RColorBrewer palette names, default is OrRd with 9 colors Use more/less colors (n) for a bigger/smaller range, i.e. more/less extremes at each end. Colors are ordered according to the order of factor levels. If namesFrom given, add names to colors; otherwise, add names(x) or x.

Usage

1
brewPalFac(x, n = 9, name = "OrRd", pull = NULL, namesFrom = NULL)

Arguments

x

Numeric vector/factor with optional names.

n

Number of colors for RColorBrewer (depends on the name).

name

Name of the RColorBrewer palette.

pull

Indices to pull colors from RColorBrewer::brewer.pal

namesFrom

Vector of names to be added to colors; default is names(x) or x.

Value

Named factor of colors of the same length as x where the order of colors corresponds to the order of x.

Implementation

Levels of x are ordered as they apper in data; this is achieved by as.factor(x, levels=unique(x)) In the 2nd to the last line, we create a factor from colsn with levels ordered as they appear; In the last line, we reorder the levels of that factor according to the order of levels in x; xtfrm(unique(x)) reports indices of (unique) values in levels.


peterjuv/myHelpers documentation built on June 12, 2021, 1:44 p.m.