def: Definition of Vectors for Plotting or Annotating

Description Usage Arguments Details Value Author(s) Examples

View source: R/def.R

Description

This function can be used to define vectors to annotate a set of taxon names, labels, etc. It should facilitate the (re)definition of colours or similar attributes for plotting trees or other graphics.

Usage

1
def(x, ..., default = NULL, regexp = FALSE)

Arguments

x

a vector of mode character.

...

a series of statements defining the attributes.

default

the default to be used (see details).

regexp

a logical value specifying whether the statements defined in ... should be taken as regular expressions.

Details

The idea of this function is to make the definition of colours, etc., simpler than what is done usually. A typical use is:

def(tr$tip.label, Homo_sapiens = "blue")

which will return a vector of character strings all "black" except one matching the tip label "Homo_sapiens" which will be "blue". Another use could be:

def(tr$tip.label, Homo_sapiens = 2)

which will return a vector a numerical values all 1 except for "Homo_sapiens" which will be 2. Several definitions can be done, e.g.:

def(tr$tip.label, Homo_sapiens = "blue", Pan_paniscus = "red")

The default value is determined with respect to the mode of the values given with the ... (either "black" or 1).

If regexp = TRUE is used, then the names of the statements must be quoted, e.g.:

def(tr$tip.label, "^Pan_" = "red", regexp = TRUE)

will return "red" for all labels starting with "Pan_".

Value

a vector of the same length than x.

Author(s)

Emmanuel Paradis

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
data(bird.orders)
a <- def(bird.orders$tip.label, Galliformes = 2)
str(a) # numeric
plot(bird.orders, font = a)
co <- def(bird.orders$tip.label, Passeriformes = "red", Trogoniformes = "blue")
str(co) # character
plot(bird.orders, tip.color = co)
### use of a regexp (so we need to quote it) to colour all orders
### with names starting with "C" (and change the default):
co2 <- def(bird.orders$tip.label, "^C" = "gold", default = "grey", regexp = TRUE)
plot(bird.orders, tip.color = co2)

ape documentation built on Sept. 24, 2018, 9:03 a.m.