var.in.colour: Creates a colour variable corresponding to a factor.

Description Usage Arguments Value See Also Examples

Description

Creates a variable with each entry assuming a different colour, corresponding to levels of a factor. Such a variable is convenient for use with plotting. The colours chosen are picked by rainbow, given the number of factor levels.

Usage

1
var.in.colour(myclass, mystart = 0.1, myend = 0.9)

Arguments

myclass

a factor, or a variable that can be considered as (and transformed into) a factor. Observations that are NA for the input variable are also NA for the resulting colour variable.

mystart

the starting value for the colour range from rainbow. Must be a value between 0 and 1.

myend

the end value for the colour range from rainbow. Must be a value between 0 and 1.

Value

A list with the following slots: col_var, containing the variable with the colours, with as many entries as the input variable myclass; list_cols, a vector of colours used, as long as the number of levels/distinct values in myclass; and levels_class, a vector containing the categories of myclass, in the same order as in list_cols.

See Also

rainbow

Examples

1
2
3
4
5
6
7
8
# Create a factor
fcl <- factor(rep(5:3,each=3))
# Now create a vector of colours, one corresponding to each factor level
# as well as objects to be used in a legend
col.cl <- var.in.colour(fcl)
# Make a simple plot displaying the colours and add a legend
plot(as.numeric(as.character(fcl)), col=col.cl[["col_var"]], pch=20, cex=2)
legend("topright", legend=col.cl[["levels_class"]], pch=20, col=col.cl[["list_cols"]] )

rxmenezes/rscreenorm documentation built on May 15, 2019, 1:19 p.m.