PhyloTree displays phylogenetic trees with support for multiple input formats, branch styles, and orientation options. Trees can be rendered as rectangular dendrograms, slanted cladograms, or circular radial layouts.
When to Use
Phylogenetic trees are ideal for:- Evolutionary relationships — species phylogenies, gene families, viral evolution
- Hierarchical clustering — sample dendrograms, distance-based trees
- Taxonomic classification — organism classification trees
- Gene trees — orthologs, paralogs, domain evolution
- Structural relationships — protein family trees, structural clustering
Basic Example
Input Formats
Newick Format
Parse standard Newick strings with branch lengths and support values:- Branch lengths (
:1.0) - Bootstrap/posterior support values on internal nodes
- Arbitrarily nested subtrees
- Optional labels on internal nodes
Edge List
Build a tree from(parent_label, child_label, branch_length) tuples:
Distance Matrix (UPGMA)
Build a tree by UPGMA clustering of a symmetric distance matrix:Linkage Matrix
Build from a scipy/R-style linkage matrix where each row is[left_idx, right_idx, distance, n_leaves]:
0..n-1 are the original leaves; n.. are internal nodes.
Tree Styles
Rectangular (Default)
Right-angle elbows at the parent depth:Slanted
Single diagonal line from parent to child:Circular (Radial)
Polar projection for large trees:Orientations
Control which side the root appears on:Phylogram Mode
By default, trees are rendered as cladograms (all leaves aligned). Enable phylogram mode to use branch lengths for the depth axis:Clade Coloring
Color entire subtrees (clades) to highlight taxonomic groups:Support Values
Display bootstrap or posterior probability values on internal nodes:(A,B)95 → support = 95).
Styling Options
Key Methods
PhyloTree::from_newick(s: &str)
Parse a Newick-format string. Supports branch lengths (:1.0), support values on internal nodes, and arbitrarily nested subtrees.
PhyloTree::from_edges(edges: &[(S, S, f64)])
Build from (parent_label, child_label, branch_length) edges. Root is the node that never appears as a child.
PhyloTree::from_distance_matrix(labels: &[&str], dist: &[Vec<f64>])
Build by UPGMA clustering of a symmetric distance matrix.
PhyloTree::from_linkage(labels: &[&str], linkage: &[[f64; 4]])
Build from scipy/R linkage matrix. Each row is [left_idx, right_idx, distance, n_leaves].
.with_orientation(o: TreeOrientation)
Set which side the root appears on: Left (default), Right, Top, or Bottom.
.with_branch_style(s: TreeBranchStyle)
Set branch drawing style: Rectangular (default), Slanted, or Circular.
.with_phylogram()
Enable phylogram mode — use branch lengths for the depth axis instead of equal spacing.
.with_branch_color<S: Into<String>>(c: S)
Set color for all branch lines. Accepts any CSS color string.
.with_leaf_color<S: Into<String>>(c: S)
Set text color for leaf labels.
.with_support_threshold(t: f64)
Show support values (bootstrap/posterior) >= threshold. Set to None to hide all support values.
.with_clade_color<S: Into<String>>(node_id: usize, color: S)
Color the entire subtree rooted at node_id. Use this to highlight taxonomic groups or clades of interest.
.with_legend<S: Into<String>>(label: S)
Enable a legend (useful with clade colors).
.leaf_labels_top_to_bottom() -> Vec<String>
Return leaf labels in top-to-bottom render order. Use this to set y_categories on a side-by-side Heatmap for row alignment:
Data Structures
PhyloTree
PhyloNode
TreeOrientation
TreeBranchStyle
Tips
- Large trees: Use circular layout for 15+ taxa to avoid label overlap
- Phylogram vs cladogram: Use phylogram when branch lengths are meaningful (evolutionary time, genetic distance)
- Support values: Display bootstrap/posterior values to indicate confidence in internal branches
- Clade coloring: Highlight major taxonomic groups or functional categories
- Alignment with heatmaps: Use
.leaf_labels_top_to_bottom()to get leaf order for heatmap row ordering - Branch styles: Rectangular is most common in phylogenetics; slanted saves space; circular works for radial layouts
- Newick format: Most phylogeny software exports Newick; test your parser with edge cases (missing branch lengths, support values)
Related Plots
- Heatmap — Often paired with phylogenetic trees for expression data
- Dendrogram — Hierarchical clustering trees (same underlying structure)