View source: R/plot-timetree.R
| plot_timetree | R Documentation |
The main entry point of Rclade. Takes a phylogenetic tree object or file path and produces a publication-ready visualization with automatic taxonomic collapsing, geological timescale integration, and smart legend layout.
plot_timetree(
tree,
tree_index = NULL,
multi_tree_mode = "error",
rank = "none",
triangle_mode = "mixed",
space_mode = "proportional",
layout = "rectangular",
angle = 360,
color_palette = "viridis",
color_mapping = NULL,
line_width = 1,
show_tip_labels = FALSE,
tip_label_size = 2,
add_timescale = TRUE,
timescale_levels = c("eras", "eons"),
unit = NULL,
taxonomy_format = "auto",
custom_patterns = NULL,
taxonomy_file = NULL,
taxonomy_file_sep = "auto",
taxonomy_file_header = FALSE,
taxonomy_file_priority = TRUE,
taxonomy_source_priority = NULL,
taxonomy_table_sep = ";",
taxonomy_delimiter_mode = "reverse",
legend_position = "bottom",
legend_nrow = NULL,
legend_ncol = NULL,
legend_title = NULL,
clade = NULL,
strict = FALSE,
groups = NULL,
show_clade_label = FALSE,
show_clade_count = TRUE,
clade_label_offset = 50,
clade_label_fontsize = 3,
show_support = FALSE,
support_threshold = 0.95,
show_hpd = FALSE,
hpd_color = "firebrick",
geo_events = FALSE,
timescale_version = "ICS 2023/02",
main_title = NULL,
sub_title = NULL,
highlight = NULL,
highlight_alpha = 0.2,
theme_fun = theme_timetree,
output = NULL,
overwrite = "ask",
width = 14,
height = 10,
taxonomy_levels = NULL,
low_memory = FALSE,
ignore_malformed = FALSE,
ignore_branch_length = FALSE,
color_rank = NULL,
timescale_mode = "radial",
timescale_position = "right",
tree_start_position = "right",
opts = NULL
)
tree |
A |
tree_index |
Integer. Index of tree to use from multiPhylo objects (e.g., BEAST posterior).
Only used when |
multi_tree_mode |
Character. How to handle multiple trees in a file.
Options: |
rank |
Taxonomic rank to collapse at. One of:
|
triangle_mode |
Collapse triangle visualization mode.
|
space_mode |
Space allocation strategy for collapsed clades.
|
layout |
Tree layout. |
angle |
Fan angle in degrees for circular layout (0-360).
Only used when |
color_palette |
Color palette specification. Can be:
|
color_mapping |
Named character vector of specific color assignments.
Takes highest priority over |
line_width |
Branch line width (passed to ggtree). Default: |
show_tip_labels |
Logical. Whether to display tip labels.
Default: |
tip_label_size |
Numeric. Tip label font size. Default: |
add_timescale |
Logical. Whether to add a geological timescale to the x-axis.
Requires rectangular layout and valid edge lengths. Default: |
timescale_levels |
Character vector of timescale levels to display.
Options: |
unit |
Time unit of input tree edge lengths: |
taxonomy_format |
Taxonomy label format. |
custom_patterns |
Named list of regex patterns for custom format parsing.
Required when |
taxonomy_file |
Character. Path to an external taxonomy file. The file
should have two columns: (1) tip labels and (2) taxonomy strings in GTDB
format (e.g., |
taxonomy_file_sep |
Character. Column separator for taxonomy file.
|
taxonomy_file_header |
Logical. Whether taxonomy file has a header row.
Default: |
taxonomy_file_priority |
Logical. If |
taxonomy_source_priority |
Character. Which taxonomy source takes priority
when both embedded (label-based) and table (file-based) taxonomy are available:
|
taxonomy_table_sep |
Character. Separator between taxonomy ranks in the
second column of an external taxonomy file. Default: |
taxonomy_delimiter_mode |
Character. Embedded (Format A) parsing strategy:
|
legend_position |
Legend placement. Can be a cardinal direction
( |
legend_nrow |
Integer. Number of rows in legend grid. Auto-computed if NULL. |
legend_ncol |
Integer. Number of columns in legend grid. Auto-computed if NULL. |
legend_title |
Character. Custom legend title. If |
clade |
Character. Specific clade name to collapse (e.g., "Cyanobacteriota").
When provided, only this clade is checked for monophyly and collapsed if valid.
Mutually exclusive with |
strict |
Logical. If |
groups |
Named list of custom tip groups for collapsing. Each element
is a character vector of tip labels belonging to that group. Groups must be
monophyletic; non-monophyletic groups will raise an error. When |
show_clade_label |
Logical. Whether to add clade labels next to collapsed
triangles showing group name and species count. Default: |
show_clade_count |
Logical. Whether to show species count in clade labels
(e.g., "Proteobacteria (n=42)"). Only used when |
clade_label_offset |
Numeric. Horizontal offset for clade labels from the
right edge of the collapsed triangle in Ma units (0-5000). Default: |
clade_label_fontsize |
Numeric. Font size for clade labels (1-20).
Default: |
show_support |
Logical. Whether to display node support values.
Requires treedata input with posterior/bootstrap annotations.
Default: |
support_threshold |
Numeric. Minimum support value to display (0-1).
Default: |
show_hpd |
Logical. Whether to display HPD (Highest Posterior Density)
intervals. Requires node data with HPD annotations. Default: |
hpd_color |
Color for HPD bars. Default: |
geo_events |
Data frame of geological events to annotate, with columns
|
timescale_version |
Geological timescale version string. Currently only
|
main_title |
Character. Main title for the plot. Default: |
sub_title |
Character. Subtitle for the plot. Default: |
highlight |
Character vector of group names to highlight with colored
backgrounds. Only monophyletic groups are highlighted; non-monophyletic
groups trigger a warning. Supports special identifiers:
|
highlight_alpha |
Numeric. Transparency of highlight color (0-1).
Default: |
theme_fun |
Theme function or NULL. Default: |
output |
Optional output file path. If provided, the plot is saved
immediately (backward compatibility). Default: |
overwrite |
Character. Overwrite mode when |
width |
Output width in inches. Default: |
height |
Output height in inches. Default: |
taxonomy_levels |
Optional list for custom taxonomy rank codes and
names, e.g. |
low_memory |
Logical. If |
ignore_malformed |
Logical. If |
ignore_branch_length |
Logical. If |
color_rank |
Character. Taxonomic rank for coloring, independent of
|
timescale_mode |
Character. Timescale display mode for circular layout:
|
timescale_position |
Character. Clock position of the timescale axis
when |
tree_start_position |
Character. Clock position where the tree starts
expanding (the gap between the last and first tip). One of |
opts |
A |
This function orchestrates the complete Rclade pipeline:
Input validation and reading (format detection, unit conversion)
Taxonomy parsing (GTDB/Silva/NCBI/custom, clade/groups/rank modes)
MRCA computation and monophyly check (with nesting conflict detection)
Color generation (color-blind-safe palette)
Tree rendering and batch clade collapsing (ggtree + depth-first collapse)
Timescale integration and annotations (deeptime, support, HPD, labels, highlight)
Plot finalization (legend, theme, title, save, metadata)
A ggplot object with an rclade_info attribute containing
metadata (tip count, group count, taxonomy format, etc.).
Can be further customized with + layers.
When tree is a file path, Newick labels longer than 500 characters
are truncated to 400 characters plus a _RCLADE_TRUNC suffix (with a
warning) before parsing, because ape's Newick parser aborts the whole R
process on labels longer than ~512 characters on Linux. Truncated labels
may no longer match external taxonomy files or sequence IDs; shorten
labels upstream if exact matching is required. See read_tree_auto().
For complex configurations, consider organizing parameters by category:
Tree input: tree
Collapsing: rank, triangle_mode, space_mode
Layout: layout, angle, line_width
Colors: color_palette, color_mapping
Labels: show_tip_labels, tip_label_size, show_clade_label, clade_label_offset
Timescale: add_timescale, timescale_levels, unit
Taxonomy: taxonomy_format, custom_patterns
Annotations: show_support, support_threshold, show_hpd
Legend: legend_position, legend_nrow, legend_ncol
Output: output, width, height
Yu G, Smith DK, Zhu H, Guan Y, Lam TT-Y (2017). "ggtree: an R package for visualization and annotation of phylogenetic trees with their covariates and other associated data." Methods in Ecology and Evolution, 8(1), 28-36. doi:10.1111/2041-210X.12628
Gearty W (2025). "deeptime: an R package that facilitates highly customizable and reproducible visualizations of data over geological time intervals." Big Earth Data. doi:10.1080/20964471.2025.2537516
Paradis E, Schliep K (2019). "ape 5.0: an environment for modern phylogenetics and evolutionary analyses in R." Bioinformatics, 35(3), 526-528. doi:10.1093/bioinformatics/bty633
# Quick start with the bundled example tree (no timescale)
data(example_tree)
p <- plot_timetree(example_tree, rank = "phylum",
taxonomy_format = "GTDB", add_timescale = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.