mergeMappedStates2: Rename, merge, or split mapped states

Description Usage Arguments Details Value Examples

View source: R/mergeMappedStates2.R

Description

This function renames, merges, or splits mapped states on a tree.

Usage

1
mergeMappedStates2(tree, old.states, new.state, node = NULL)

Arguments

tree

an object of class "simmap" or "multiSimmap" containing one or more phylogenetic trees with a mapped discrete character

old.states

state(s) to rename or merge

new.state

name for new state

node

a node index, used to specify a subclade of interest

Details

If node is specified, only mapped states of descendants edges of that node are modified. This function is based on the similarly named utility function by Liam Revell in phytools.

Value

An object of class "simmap" or "multiSimmap".

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
library(phytools)
# simulate a mapped tree
set.seed(4)
Q <- matrix(c(-2,1,1,1,-2,1,1,1,-2),3,3)
rownames(Q) <- colnames(Q) <- letters[1:3]
tree <- sim.history(pbtree(n=100,scale=1),Q)
cols <- setNames(c("blue","red","green","orange"),letters[1:4])

# plot the mapping
plot(tree, cols, ftype="i", fsize=0.7)

# split state c to state d within subclade
tree2 <- mergeMappedStates2(tree, "c", "d", 173)

# plot the new mapping
plot(tree2, cols, ftype="i", fsize=0.7)

willgearty/pcmtools documentation built on Nov. 5, 2019, 12:20 p.m.