tree_subset: Subset tree objects by related nodes

Description Usage Arguments Details Examples

View source: R/tree-subset.R

Description

This function allows for a tree object to be subset by specifying a node and returns all related nodes within a selected number of levels

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
tree_subset(
  tree,
  node,
  levels_back = 5,
  group_node = TRUE,
  group_name = "group",
  root_edge = TRUE
)

## S3 method for class 'phylo'
tree_subset(
  tree,
  node,
  levels_back = 5,
  group_node = TRUE,
  group_name = "group",
  root_edge = TRUE
)

## S3 method for class 'treedata'
tree_subset(
  tree,
  node,
  levels_back = 5,
  group_node = TRUE,
  group_name = "group",
  root_edge = TRUE
)

Arguments

tree

a tree object of class phylo

node

either a tip label or a node number for the given tree that will be the focus of the subsetted tree

levels_back

a number specifying how many nodes back from the selected node the subsetted tree should include

group_node

whether add grouping information of selected node

group_name

group name (default 'group') for storing grouping information if group_node = TRUE

root_edge

If TRUE (by default), set root.edge to path length of orginal root to the root of subset tree

Details

This function will take a tree and a specified node from that tree and subset the tree showing all relatives back to a specified number of nodes. This function allows for a combination of ancestor and offspring to return a subsetted tree that is of class phylo. This allows for easy graphing of the tree with ggtree

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
## Not run: 
  nwk <- system.file("extdata", "sample.nwk", package="treeio")
  tree <- read.tree(nwk)

  sub_tree <- tree_subset(tree, node = "A", levels_back = 3)
  ggtree(sub_tree) + geom_tiplab() + geom_nodelab()

## End(Not run)

## Not run: 
  nwk <- system.file("extdata", "sample.nwk", package="treeio")
  tree <- read.tree(nwk)

  sub_tree <- tree_subset(tree, node = "A", levels_back = 3)
  ggtree(sub_tree) + geom_tiplab() + geom_nodelab()

## End(Not run)

treeio documentation built on Nov. 21, 2020, 2:01 a.m.