Skip to contents

Converts a tree to an igraph graph, with the tree's nodes as vertices and its branches as edges, and attaches to each tip the row of data with the same accession. This is what gtdb_tree_plot() draws; use it directly to build your own figure with ggraph::ggraph().

Usage

gtdb_tree_graph(tree, data = NULL, taxon = "accession", taxonomy = TRUE)

Arguments

tree

A GTDB tree, usually pruned with gtdb_tree_prune().

data

Optional data frame with at most one row per taxon, e.g. the output of gtdb_summarise_draws().

taxon

Column of data holding the accessions that match the tips.

taxonomy

If TRUE (the default), add the tips' GTDB lineage read from the tree.

Value

An igraph graph.

Details

Vertex attributes:

name

the accession (tips) or "node<number>" (internal nodes).

node, is_tip

the node number in tree, and whether it is a tip. (ggraph layouts add leaf, which is the same as is_tip.)

node_support, node_taxa

for internal nodes, the GTDB support value and clade names (see gtdb_node_labels()).

n_tips

the number of tips descending from the node (1 for tips).

domain ... genus

with taxonomy = TRUE, each tip's GTDB lineage from gtdb_tip_taxonomy(), for the ranks data does not already have.

the columns of data

for tips with a row in data; NA otherwise. Columns whose names clash with the attributes above (or with x, y, leaf and circular, which layouts add) get a _data suffix.

The edge attribute branch_length holds the branch lengths.

Examples

tree <- gtdb_tree_read(gtdb_example("tree"))
estimates <- gtdb_summarise_draws(read.csv(gtdb_example("draws")),
                                  value = "effect")
g <- gtdb_tree_graph(tree, estimates)
g
#> IGRAPH 1d6ec4b DN-- 1120 1119 -- 
#> + attr: name (v/c), node (v/n), is_tip (v/l), node_support (v/n),
#> | node_taxa (v/c), n_tips (v/n), domain (v/c), phylum (v/c), class
#> | (v/c), order (v/c), family (v/c), genus (v/c), accession (v/c),
#> | estimate (v/n), .lower (v/n), .upper (v/n), .width (v/n), n_draws
#> | (v/n), branch_length (e/n)
#> + edges from 1d6ec4b (vertex names):
#>  [1] node561->node562         node562->node563         node563->node564        
#>  [4] node564->node565         node565->node566         node566->node567        
#>  [7] node567->node568         node568->node569         node569->node570        
#> [10] node570->GCF_037023725.1 node570->GCF_900105835.1 node569->GCF_001042985.1
#> + ... omitted several edges

# a figure of your own with ggraph
library(ggraph)
#> Loading required package: ggplot2
ggraph(g, layout = "dendrogram", circular = TRUE) +
  geom_edge_elbow(colour = "grey70") +
  geom_node_point(aes(filter = is_tip, colour = phylum), size = 0.8) +
  coord_fixed() +
  theme_void()