View source: R/geom_text_phylo.R
| geom_text_clade | R Documentation |
This geom adds labels and corresponding vertical bars to specified clades of
a phylogenetic tree that has been plotted using ggtree::ggtree(). It is
therefore very similar to ggtree::geom_cladelab(). However, unlike
ggtree::geom_cladelab(), this geom is intended to work with all coordinate
systems, including coord_geo() and coord_geo_radial().
geom_text_clade(
mapping = NULL,
data = NULL,
text_geom = "text",
stat = "identity",
position = "identity",
...,
parse = FALSE,
auto_adjust = TRUE,
extend = c(0, 0),
check_overlap = FALSE,
lineend = "butt",
na.rm = TRUE,
show.legend = NA,
inherit.aes = TRUE
)
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
text_geom |
Which geom to use for the text labels. Valid options are
"text" for |
stat |
The statistical transformation to use on the data for this layer.
When using a
|
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
... |
Other arguments passed on to
|
parse |
If |
auto_adjust |
Should upside-down text labels automatically be rotated 180° to improve readability? |
extend |
A numeric vector of length 2 indicating how much to extend the vertical bar beyond the minimum and maximum y-values of the clade. The first value extends the bar above the maximum y-value, and the second value extends the bar below the minimum y-value. |
check_overlap |
If |
lineend |
Line end style (round, butt, square). |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
The clades to be labeled are specified using the node aesthetic which
identifies the most recent common ancestor of the clade. The label
aesthetic specifies the text label for each clade. The ggfun::%<+%()
operator should be used to combine custom clade labels with the tree (see
Examples). If no nodes are specified, a label will be added to every tip
by default (like geom_text_phylo()).
The vertical bar for each clade extends from the minimum to the maximum
y-values of all descendant nodes of the specified node, with optional
extensions above and below these values controlled by the extend parameter.
Each label will be plotted center aligned and perpendicular to its
corresponding bar by default. The angle, hjust, and vjust aesthetics
can be used to adjust this. If custom angle values are specified, these
will be added to the default angle as calculated as described above.
As with ggplot2::geom_text(), the limits of axes will not be
expanded to accommodate the new labels, so you may need to extend them
manually using the limits or expand arguments within scale_ or coord_
functions. Note that coord_geo() by default sets expand = FALSE.
geom_text_phylo() understands the following
aesthetics (required aesthetics are in bold):
x (pulled from the phylogeny by default)
y (pulled from the phylogeny by default)
parent (pulled from the phylogeny by default)
node (pulled from the phylogeny by default)
label (pulled from the phylogeny by default)
alpha
angle
color/colour
family
fontface
group
hjust
lineheight
size
vjust
You can modify text alignment with the vjust and hjust aesthetics. These
can either be a number between 0 (left/bottom) and 1 (right/top) or a
character ("left", "middle", "right", "bottom", "center", "top").
There are two special alignments: "inward" and "outward". Inward always
aligns text towards the center, and outward aligns it away from the center.
Note that numeric values outside of [0, 1] will also work and will move the
text beyond the normal alignment positions (e.g., the default hjust value
is -0.02).
library(ggplot2)
library(ggtree)
library(phytools)
data(primate.tree)
# single annotation
revts(ggtree(primate.tree)) +
geom_text_clade(label = "Hominoidea", node = 114, extend = c(0.1, 0.1)) +
coord_geo_radial()
# data frame of clade labels
clades.df <- data.frame(
clade = c("Lorisoidea", "Lemuroidea", "Tarsioidea", "Ceboidea",
"Cercopithecoidea", "Hominoidea"),
node = c(166, 146, 144, 120, 95, 114)
)
revts(ggtree(primate.tree)) %<+% clades.df +
geom_text_clade(aes(label = clade), extend = c(0.1, 0.1)) +
coord_geo_radial()
# display with other tip data
data(primate.data)
activity <- subset(primate.data, select = "Activity_pattern")
revts(gheatmap(ggtree(primate.tree), activity, offset = -70,
colnames = FALSE, width = 0.03, color = NA)) %<+% clades.df +
geom_text_clade(aes(label = clade), extend = c(0.1, 0.1),
position = position_nudge(x = 10)) +
coord_geo_radial()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.