Skip to contents

Draws the tree with each tip that has a row in data as a point filled by value, for example the posterior median of a taxon-level contrast from a phylogenetic model fitted elsewhere (see gtdb_summarise_draws()). Taxa above (or below) a threshold can be highlighted with a dark outline and labelled, and GTDB clades named.

Usage

gtdb_tree_plot(
  tree,
  data,
  value = "estimate",
  taxon = "accession",
  layout = c("unrooted", "rectangular", "circular"),
  branch_lengths = TRUE,
  highlight = c("none", "above", "below"),
  threshold = NULL,
  highlight_by = c("estimate", "interval"),
  lower = ".lower",
  upper = ".upper",
  label = "{genus}\n({accession})",
  label_tips = c("highlighted", "all", "none"),
  label_size = 2,
  max_overlaps = 30,
  clade_rank = NULL,
  clade_min_tips = 10,
  clade_label_size = 2.5,
  palette = "plasma",
  transform = "identity",
  breaks = ggplot2::waiver(),
  limits = NULL,
  point_size = 2,
  alpha = TRUE,
  show_missing = FALSE,
  highlight_colour = "grey20",
  edge_colour = "grey70",
  edge_width = 0.3,
  fill_label = NULL,
  legend_position = c(0.12, 0.85),
  layout_args = list()
)

Arguments

tree

A GTDB tree, usually pruned with gtdb_tree_prune().

data

A data frame with one row per taxon, holding taxon and value, e.g. from gtdb_summarise_draws().

value

Column of data to fill the tips by. Defaults to "estimate", the point estimate from gtdb_summarise_draws().

taxon

Column of data holding the accessions that match the tips.

layout

"unrooted", "rectangular" or "circular".

branch_lengths

If TRUE (the default), draw branch lengths to scale.

highlight

"none" (the default), "above" or "below": which tips to outline and label, relative to threshold.

threshold

Value of value (or of the interval, see highlight_by) that tips must reach to be highlighted. Required unless highlight = "none".

highlight_by

"estimate" (compare value with threshold) or "interval" (compare the credible interval, columns lower and upper).

lower, upper

Columns of data holding the credible interval, for highlight_by = "interval".

label

Template for the tip labels; see Details. NULL for none.

label_tips

Which tips to label: "highlighted" (the default), "all" tips with a value, or "none".

label_size

Text size of the tip labels.

max_overlaps

Passed to ggrepel: labels that would overlap more than this many others are dropped.

clade_rank

Optional GTDB rank to name clades at: "phylum", "class", "order", "family" or "genus".

clade_min_tips

Only name clades with at least this many tips.

clade_label_size

Text size of the clade names.

palette

A viridis palette option for the fill scale, e.g. "plasma" (the default), "viridis" or "turbo".

transform

Transformation of the fill scale, e.g. "identity" (the default), "sqrt" or "log10", or a scales transformation object.

breaks, limits

Breaks and limits of the fill scale.

point_size

Size of the tip points.

alpha

If TRUE (the default), make tip transparency follow value; see Details.

show_missing

If TRUE, draw tips without a value as small grey points.

highlight_colour

Outline colour of highlighted tips.

edge_colour, edge_width

Colour and width of the branches.

fill_label

Title of the fill legend (Markdown, via ggtext; use <br> for line breaks). Defaults to a title made from value.

legend_position

Where to put the legend: two numbers between 0 and 1 to place it inside the plot (the default, c(0.12, 0.85), is the top left), or "right", "bottom", "none", etc.

layout_args

A list of further arguments for the ggraph layout.

Value

A ggplot object. Its data element holds the layout: one row per node, with its coordinates and the attributes described in gtdb_tree_graph(), plus .value, .highlight, .tip_label and .clade_label.

Details

Layouts. "unrooted" (the default) spreads the tree out from its centre, with no root, which suits trees of hundreds of taxa from many phyla. "rectangular" draws a rooted tree with the root on the left and the tips on the right, and "circular" the same tree around a circle. With branch_lengths = TRUE, branch lengths are drawn to scale (expected substitutions per site in the GTDB marker alignment); otherwise only the branching order is shown. Arguments of the ggraph layout (e.g. daylight = FALSE for a faster unrooted layout) go in layout_args.

Highlighting. With highlight = "above", tips with value >= threshold are outlined in highlight_colour and labelled; with "below", tips with value <= threshold. With highlight_by = "interval", a tip is highlighted only if its whole credible interval (lower to upper) is above (or below) threshold, so highlighting reflects posterior certainty rather than the point estimate alone. With alpha = TRUE, the points' transparency also follows value, so the highlighted end of the scale stands out: high values are opaque with "above" (and "none"), low values with "below".

Labels. label is a template in which {column} is replaced by the tip's value of that column of data or, for the ranks domain to genus, of the GTDB lineage read from the tree (see gtdb_tree_graph()). The default, "{genus}\n({accession})", gives the genus with the accession below it. Labels are placed with ggrepel to avoid overlaps; labels that cannot be placed are dropped (raise max_overlaps to keep more).

Clades. clade_rank = "phylum" names each GTDB phylum with at least clade_min_tips tips in the tree: at the node where it starts, or, in the unrooted layout (where those nodes crowd the centre), at the centre of its tips.

The result is an ordinary ggplot object: change it with +, e.g. + ggplot2::scale_fill_distiller(palette = "RdBu") for a diverging fill scale (ggplot2 notes that it replaces the existing scale), and save it with ggplot2::ggsave().

See also

gtdb_summarise_draws() for the estimates, gtdb_tree_prune() for the tree, and gtdb_tree_graph() to build other figures.

Examples

tree <- gtdb_tree_read(gtdb_example("tree"))
draws <- read.csv(gtdb_example("draws"))
estimates <- gtdb_summarise_draws(draws, value = "effect")

# taxa whose estimate is at least 0.2, highlighted and labelled
gtdb_tree_plot(tree, estimates, highlight = "above", threshold = 0.2,
               fill_label = "Simulated<br>effect")


# taxa whose 95% interval lies below 0.01, on a rectangular tree
gtdb_tree_plot(tree, estimates, layout = "rectangular",
               highlight = "below", threshold = 0.01,
               highlight_by = "interval", clade_rank = "phylum",
               legend_position = "right")