
Add PhyloPics to a phylogenetic tree plotted with base R
Source:R/add_phylopic_tree.R
add_phylopic_tree.RdSpecify existing images, taxonomic names, or PhyloPic uuids to add PhyloPic silhouettes alongside the associated leaves of a phylogenetic tree that has been plotted in the active graphics device using the base R graphics functions. The current functionality assumes that the tree is not in a circular configuration and has a "rightwards" direction.
Usage
add_phylopic_tree(
tree,
tip = names(img) %||% names(uuid) %||% names(name) %||% name,
img = NULL,
name = if (is.null(img) && is.null(uuid)) tip else NULL,
uuid = NULL,
align = "tip",
width,
padding = NULL,
relWidth = 0.06,
relPadding = if (align == "tip") 1/200 else -1/200,
hjust = if (align == "tip") 0 else 1,
...
)Arguments
- tree
phylo. The phylogenetic tree object on which to add the silhouette.- tip
character. The tip labels against which to add the silhouettes. If not specified, the names of theimg,uuidornamevector are used.- img
A Picture or png array object, e.g., from using
get_phylopic().- name
character. A taxonomic name to be passed toget_uuid().- uuid
character. A valid uuid for a PhyloPic silhouette (such as that returned byget_uuid()orpick_phylopic()).- align
character. Should each silhouette be aligned to its respective tip ("tip", the default) or to the right-hand side of the plotting area ("plot")? If"tip"is specified, the silhouette is placed at the x coordinate of the respective tip, plus any horizontal padding specified bypaddingorrelPadding. If"plot"is specified, the silhouette is placed at the right-hand side of the plotting area, determined bypar("usr"), plus any horizontal padding specified bypaddingorrelPadding.- width, relWidth
numeric. The width of each silhouette, in the plot coordinate system (width) or relative to the size of the plotting area (relWidth). If "NULL" andheightis specified, the width is determined by the aspect ratio of the original image. One of height and width must be "NULL".- padding, relPadding
numeric. Horizontal padding for each silhouette from its respective x value, in the plot coordinate system (padding) or relative to the size of the plotting area (relPadding). Negative values offset to the left.- hjust
numeric. A numeric vector between 0 and 1 specifying horizontal justification (left = 0, center = 0.5, right = 1).- ...
Further arguments to pass to
add_phylopic_base().
See also
For trees plotted using ggtree, see geom_phylopic().
Examples
if (FALSE) { # \dontrun{
# Load the ape library to work with phylogenetic trees
library("ape")
# Read a phylogenetic tree
tree <- ape::read.tree(text = "(cat, (dog, mouse));")
# Set a large right margin to accommodate the silhouettes
par(mar = c(1, 1, 1, 10))
# Plot the tree
plot(tree)
# Add a PhyloPic silhouette of a cat to the tree
add_phylopic_tree(
tree, # Must be the tree that was plotted
"cat", # Which leaf should the silhouette be plotted against?
uuid = "23cd6aa4-9587-4a2e-8e26-de42885004c9", # Silhouette to plot
relWidth = 0.2,
fill = "brown"
)
} # }