Draws phylorug rug plots (and dots) on top of a tree drawn by another
plotting function, such as ape::plot.phylo() or the phytools functions
plotTree(), plotSimmap() and contMap(). Use it when you want to keep
the other function's options (painted branches, mapped traits, branch
colours) and only add the rug plots. plot_phylorug() remains the
one-call option that draws the tree, rug plots and legends together.
Arguments
- npm
A node presence matrix from
node_presence_matrix().- backbone
The backbone
phyloobject used to buildnpm. Used to check that the plotted tree matches.- mode
One of
"support"(default) or"presence".- support_idx
Integer. Which support matrix to use (
support_1,support_2, ...). Default1.- palette
Cell colours; see the
paletteargument ofplot_phylorug(). Default"grey".- rug_position
One of
"centre"(default),"inside"or"outside"; seeplot_phylorug().- cell_scale
Numeric. Cell height as a fraction of the tip spacing. Default
0.45.- thresholds
Optional custom thresholds; see
plot_phylorug().- dot_col, dot_cex
Colour and size of the dots. Defaults
"black"and1.- legend
Logical. If
TRUE, draws the position legend (top left) and, in support mode, the colour key (top right). Leave room for them, for example withyliminphytools::plotTree(). DefaultFALSE.- legend_cex
Numeric. Size of the legends. Default
1.
Details
ape and phytools store the position of every node of the last plotted
tree (last_plot.phylo in ape::.PlotPhyloEnv). add_rug_plots() reads
these positions, so the tree on screen must be the backbone used to build
npm (same tips and nodes in the same order). A tree with painted regimes
from phytools::paintSubTree() or a contMap object keeps the backbone's
node numbers and works. The function stops if the plotted tree does not have
the backbone's number of tips and nodes. Rightward trees (the usual
layout) are the main use; fan and radial layouts also work, but may need a
smaller cell_scale.
Dots and rug plots follow the same rules as plot_phylorug(): in presence
mode a dot marks a clade recovered by every comparison analysis; in support
mode a dot marks a clade recovered by every analysis with support in the
top tier.
Nodes not recovered by any analysis are left bare.
See also
plot_phylorug() to draw tree, rug plots and legends in one call.
Examples
backbone <- sample_trees[["70p_uce"]]
others <- sample_trees[names(sample_trees) != "70p_uce"]
npm <- node_presence_matrix(backbone, others,
support_type = c("70p_ASTRAL_partition_entropy" = "lpp",
"70p_ASTRAL_uce" = "lpp",
"70p_ghost" = "sh_alrt",
"70p_partition_entropy" = "sh_alrt"))
tmp <- tempfile(fileext = ".pdf")
grDevices::pdf(tmp, width = 9, height = 6)
# Any ape plot: here one clade's branches are coloured
cols <- rep("black", nrow(backbone$edge))
cols[ape::which.edge(backbone, backbone$tip.label[1:4])] <- "darkorange"
ape::plot.phylo(backbone, edge.color = cols, edge.width = 2,
y.lim = c(0, ape::Ntip(backbone) + 5))
add_rug_plots(npm, backbone, palette = "classic", legend = TRUE)
# With phytools (if installed)
if (requireNamespace("phytools", quietly = TRUE)) {
phytools::plotTree(backbone, ylim = c(0, ape::Ntip(backbone) + 5))
add_rug_plots(npm, backbone, palette = "okabe_ito", legend = TRUE)
}
grDevices::dev.off()
#> agg_record_1d3f32136bf8
#> 2
unlink(tmp)
