bioconductor v3.9.0 Ggtree

'ggtree' extends the 'ggplot2' plotting system which implemented

Link to this section Summary

Functions

Date2decimal

add_colorbar

annotation_image

applyLayoutDaylight

as.polytomy

collapse-ggtree

decimal2Date

expand

facet_labeller

facet_plot

facet_widths

flip

geom_aline

geom_balance

geom_cladelabel

geom_cladelabel2

geom_hilight

geom_hilight_encircle

geom_label2

geom_motif

geom_nodelab

@geom_nodelab2

geom_nodepoint

geom_point2

geom_range

geom_rootedge

geom_rootpoint

geom_segment2

geom_strip

geom_taxalink

geom_text2

geom_tiplab

geom_tiplab2

geom_tippoint

geom_tree

geom_tree2

geom_treescale

getNodeAngle.df

getNodesBreadthFirst.df

getSubtree

getSubtreeUnrooted

getSubtreeUnrooted

getSubtree.df

getTreeArcAngles

get_balance_position

get_clade_position

get_heatmap_column_position

get_taxa_name

get.path

visualizing phylogenetic tree and heterogenous associated data based on grammar of graphics ggtree provides functions for visualizing phylogenetic tree and its associated data in R.

StatBalance

gheatmap

gzoom method

gzoom

identify

inset

Equal daylight layout method for unrooted trees.

layoutEqualAngle

msaplot

multiplot

nodebar

nodeid

nodepie

open_tree

phylopic

range_format

Objects exported from other packages

revts

rotate

rotateTreePoints.data.fram

rotate_tree

scaleClade

scale_color method

scale_x_ggtree

set_hilight_legend

stat_balance

stat_hilight

subview

theme_inset

theme_tree

theme_tree2

viewClade

xlim_expand

xlim_tree

Link to this section Functions

Date2decimal

Description

convert Date to decimal format, eg "2014-05-05" to "2014.34"

Usage

Date2decimal(x)

Arguments

ArgumentDescription
xDate

Value

numeric

Author

Guangchuang Yu

%<+%

Description

add annotation data to a tree

Usage

pg %<+% data

Arguments

ArgumentDescription
pgggplot2 object
dataannotation data

Value

ggplot object with annotation data added

Author

Guangchuang Yu

Examples

nwk <- system.file("extdata", "sample.nwk", package="treeio")
tree <- read.tree(nwk)
p <- ggtree(tree)
dd <- data.frame(taxa=LETTERS[1:13],
place=c(rep("GZ", 5), rep("HK", 3), rep("CZ", 4), NA),
value=round(abs(rnorm(13, mean=70, sd=10)), digits=1))
row.names(dd) <- NULL
p %<+% dd + geom_text(aes(color=place, label=label), hjust=-0.5)

%+>%

Description

update data with tree info (y coordination and panel)

Usage

p %+>% data

Arguments

ArgumentDescription
ptree view
datadata.frame

Value

updated data.frame

Author

Guangchuang Yu

add_colorbar

Description

add colorbar legend

Usage

add_colorbar(p, color, x = NULL, ymin = NULL, ymax = NULL,
  font.size = 4)

Arguments

ArgumentDescription
ptree view
coloroutput of scale_color function
xx position
yminymin
ymaxymax
font.sizefont size

Value

ggplot2 object

Author

Guangchuang Yu

Link to this function

annotation_image()

annotation_image

Description

annotation taxa with images

Usage

annotation_image(tree_view, img_info, width = 0.1, align = TRUE,
  linetype = "dotted", linesize = 1, offset = 0)

Arguments

ArgumentDescription
tree_viewtree view
img_infodata.frame with first column of taxa name and second column of image names
widthwidth of the image to be plotted in image
alignlogical
linetypeline type if align = TRUE
linesizeline size if align = TRUE
offsetoffset of image from the tree view

Value

tree view

Author

Guangchuang Yu

Link to this function

applyLayoutDaylight()

applyLayoutDaylight

Description

Apply the daylight alorithm to adjust the spacing between the subtrees and tips of the specified node.

Usage

applyLayoutDaylight(df, node_id)

Arguments

ArgumentDescription
dftree data.frame
node_idis id of the node from which daylight is measured to the other subtrees.

Value

list with tree data.frame with updated layout using daylight algorithm and max_change angle.

as.polytomy

Description

collapse binary tree to polytomy by applying 'fun' to 'feature'

Usage

as.polytomy(tree, feature, fun)

Arguments

ArgumentDescription
treetree object
featureselected feature
funfunction to select nodes to collapse

Value

polytomy tree

Author

Guangchuang Yu

collapse-ggtree

Description

collapse a clade

Usage

list(list("collapse"), list("ggtree"))(x = NULL, node, clade_name = NULL, ...)

Arguments

ArgumentDescription
xtree view
nodeclade node
clade_nameset clade name. If clade_name = NULL, do nothing
...additional parameters

Value

tree view

Seealso

expand

Author

Guangchuang Yu

decimal2Date

Description

convert decimal format to Date, eg "2014.34" to "2014-05-05"

Usage

decimal2Date(x)

Arguments

ArgumentDescription
xnumerical number, eg 2014.34

Value

Date

Author

Guangchuang Yu

.

Description

capture name of variable

Usage

.(..., .env = parent.frame())

Arguments

ArgumentDescription
...expression
.envenvironment

Value

expression

Examples

x <- 1
eval(.(x)[[1]])

expand

Description

expand collased clade

Usage

expand(tree_view = NULL, node)

Arguments

ArgumentDescription
tree_viewtree view
nodeclade node

Value

tree view

Seealso

collapse

Author

Guangchuang Yu

Link to this function

facet_labeller()

facet_labeller

Description

label facet_plot output

Usage

facet_labeller(p, label)

Arguments

ArgumentDescription
pfacet_plot output
labellabels of facet panels

Value

ggplot object

Author

Guangchuang Yu

facet_plot

Description

plot tree associated data in an additional panel

Usage

facet_plot(p, panel, data, geom, mapping = NULL, ...)

Arguments

ArgumentDescription
ptree view
panelpanel name for plot of input data
datadata to plot by 'geom', first column should be matched with tip label of tree
geomgeom function to plot the data
mappingaes mapping for 'geom'
...additional parameters for 'geom'

Details

'facet_plot()' automatically re-arranges the input 'data' according to the tree structure, visualizes the 'data' on specific 'panel' using the 'geom' function with aesthetic 'mapping' and other parameters, and align the graph with the tree 'p' side by side.

Value

ggplot object

Author

Guangchuang Yu

Examples

tr <- rtree(10)
dd = data.frame(id=tr$tip.label, value=abs(rnorm(10)))
p <- ggtree(tr)
facet_plot(p, 'Trait', data = dd, geom=geom_point, mapping=aes(x=value))

facet_widths

Description

set relative widths (for column only) of facet plots

Usage

facet_widths(p, widths)

Arguments

ArgumentDescription
pggplot or ggtree object
widthsrelative widths of facet panels

Value

ggplot object by redrawing the figure (not a modified version of input object)

Author

Guangchuang Yu

flip

Description

flip position of two selected branches

Usage

flip(tree_view = NULL, node1, node2)

Arguments

ArgumentDescription
tree_viewtree view
node1node number of branch 1
node2node number of branch 2

Value

ggplot2 object

Author

Guangchuang Yu

geom_aline

Description

add horizontal align lines

Usage

geom_aline(mapping = NULL, linetype = "dotted", size = 1, ...)

Arguments

ArgumentDescription
mappingaes mapping
linetypeline type
sizeline size
...additional parameter

Value

aline layer

Author

Yu Guangchuang

geom_balance

Description

highlights the two direct descendant clades of an internal node

Usage

geom_balance(node, fill = "steelblue", color = "white", alpha = 0.5,
  extend = 0, extendto = NULL)

Arguments

ArgumentDescription
nodeselected node (balance) to highlight
fillcolor fill
colorcolor to outline highlights and divide balance
alphaalpha (transparency)
extendextend xmax of the rectangle
extendtoextend xmax to extendto

Details

Particularly useful when studying neighboring clades. Note that balances that correspond to multichotomies will not be displayed.

Value

ggplot2

Author

Justin Silverman

References

J. Silverman, et al. list("A phylogenetic transform enhances ", " analysis of compositional microbiota data") . (in preparation)

Link to this function

geom_cladelabel()

geom_cladelabel

Description

annotate a clade with bar and text label

Usage

geom_cladelabel(node, label, offset = 0, offset.text = 0, extend = 0,
  align = FALSE, barsize = 0.5, fontsize = 3.88, angle = 0,
  geom = "text", hjust = 0, color = NULL, fill = NA,
  family = "sans", parse = FALSE, ...)

Arguments

ArgumentDescription
nodeselected node
labelclade label
offsetoffset of bar and text from the clade
offset.textoffset of text from bar
extendextend bar height
alignlogical
barsizesize of bar
fontsizesize of text
angleangle of text
geomone of 'text' or 'label'
hjusthjust
colorcolor for clade & label, of length 1 or 2
fillfill label background, only work with geom='label'
familysans by default, can be any supported font
parselogical, whether parse label
...additional parameter

Value

ggplot layers

Author

Guangchuang Yu

Link to this function

geom_cladelabel2()

geom_cladelabel2

Description

annotate a clade with bar and text label

Usage

geom_cladelabel2(node, label, offset = 0, offset.text = 0,
  offset.bar = 0, align = FALSE, barsize = 0.5, fontsize = 3.88,
  hjust = 0, geom = "text", color = NULL, family = "sans",
  parse = FALSE, ...)

Arguments

ArgumentDescription
nodeselected node
labelclade label
offsetoffset of bar and text from the clade
offset.textoffset of text from bar
offset.baroffset of bar from text
alignlogical
barsizesize of bar
fontsizefont size of text
hjustjustify text horizontally
geomone of 'text' or 'label'
colorcolor for clade & label, of length 1 or 2
familysans by default, can be any supported font
parselogical, whether parse label
...additional parameter

Value

ggplot layers

Author

JustGitting

geom_hilight

Description

layer of hilight clade with rectangle

Usage

geom_hilight(node, fill = "steelblue", alpha = 0.5, extend = 0,
  extendto = NULL)

Arguments

ArgumentDescription
nodeselected node to hilight (required)
fillcolor fill (default = steelblue)
alphaalpha transparency, (default = 0.5)
extendextend xmax of the rectangle (default = 0)
extendtoextend xmax to extendto (default = NULL)

Value

ggplot2

Author

Guangchuang Yu

Link to this function

geom_hilight_encircle()

geom_hilight_encircle

Description

layer of hilight clade with xspline

Usage

geom_hilight_encircle(data = NULL, node, mapping = NULL,
  fill = "steelblue", alpha = 0.5, expand = 0, ...)

Arguments

ArgumentDescription
datadata frame to calculate xspline (default = NULL)
nodeselected node to hilight (required)
mappingaesthetic mapping (default = NULL)
fillcolour fill (default = steelblue)
alphaalpha (transparency) (default = 0.5)
expandexpands the xspline clade region only (default = 0)
...addtional parameters, including: 'spread' spread of shape? (default = 0.1), 'linetype' Line type of xspline (default = 1), 'size' Size of xspline line (default = 1), 's_shape' Corresponds to shape of xspline (default = 0.5), 's_open' Boolean switch determines if xspline shape is open or closed. (default = FALSE)

Value

ggplot2

geom_label2

Description

geom_label2 support aes(subset) via setup_data

Usage

geom_label2(mapping = NULL, data = NULL, ..., stat = "identity",
  position = "identity", family = "sans", parse = FALSE,
  nudge_x = 0, nudge_y = 0, label.padding = unit(0.25, "lines"),
  label.r = unit(0.15, "lines"), label.size = 0.25, na.rm = TRUE,
  show.legend = NA, inherit.aes = TRUE)

Arguments

ArgumentDescription
mappingthe aesthetic mapping
dataA layer specific dataset - only needed if you want to override the plot defaults.
...other arguments passed on to 'layer'
statName of stat to modify data
positionThe position adjustment to use for overlapping points on this layer
familysans by default, can be any supported font
parseif TRUE, the labels will be passd into expressions
nudge_xhorizontal adjustment
nudge_yvertical adjustment
label.paddingAmount of padding around label.
label.rRadius of rounded corners.
label.sizeSize of label border, in mm
na.rmlogical
show.legendlogical
inherit.aeslogical

Value

label layer

Seealso

geom_label

Author

Guangchuang Yu

geom_motif

Description

geom layer to draw aligned motif

Usage

geom_motif(mapping, data, on, ...)

Arguments

ArgumentDescription
mappingaes mapping
datadata
ongene to center (i.e. set middle position of the on gene to 0)
...additional parameters

Value

geom layer

Author

Guangchuang Yu

geom_nodelab

Description

add node label layer

Usage

geom_nodelab(mapping = NULL, nudge_x = 0, nudge_y = 0,
  geom = "text", hjust = 0.5, ...)

Arguments

ArgumentDescription
mappingaes mapping
nudge_xhorizontal adjustment to nudge label
nudge_yvertical adjustment to nudge label
geomone of 'text', 'label', 'image' and 'phylopic'
hjusthorizontal alignment, one of 0, 0.5 or 1
...additional parameters

Value

geom layer

Author

Guangchuang Yu

Link to this function

geom_nodelab2()

@geom_nodelab2

Description

add node label for circular layout

Usage

geom_nodelab2(mapping = NULL, nudge_x = 0, nudge_y = 0,
  geom = "text", hjust = 0.5, ...)

Arguments

ArgumentDescription
mappingaes mapping
nudge_xhorizontal adjustment to nudge label
nudge_yvertical adjustment to nudge label
geomone of 'text', 'label', 'image' and 'phylopic'
hjusthorizontal alignment, one of 0, 0.5 or 1
...additional parameters

Value

node label layer

Author

Guangchuang Yu

Link to this function

geom_nodepoint()

geom_nodepoint

Description

add node point

Usage

geom_nodepoint(mapping = NULL, data = NULL, position = "identity",
  na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ...)

Arguments

ArgumentDescription
mappingaes mapping
datadata
positionposition
na.rmlogical
show.legendlogical
inherit.aeslogical
...addktional parameter

Value

node point layer

Author

Guangchuang Yu

geom_point2

Description

geom_point2 support aes(subset) via setup_data

Usage

geom_point2(mapping = NULL, data = NULL, stat = "identity",
  position = "identity", na.rm = FALSE, show.legend = NA,
  inherit.aes = TRUE, ...)

Arguments

ArgumentDescription
mappingaes mapping
datadata
statName of stat to modify data
positionposition
na.rmlogical
show.legendlogical
inherit.aeslogical
...addktional parameter

Value

point layer

Seealso

geom_point

Author

Guangchuang Yu

geom_range

Description

bar of range (HPD, range etc) to present uncertainty of evolutionary inference

Usage

geom_range(range = "length_0.95_HPD", branch.length = "branch.length",
  ...)

Arguments

ArgumentDescription
rangerange, e.g. "height_0.95_HPD"
branch.lengthcorresponding branch.length
...additional parameter, e.g. color, size, alpha

Value

ggplot layer

Author

Guangchuang Yu

Link to this function

geom_rootedge()

geom_rootedge

Description

display root edge

Usage

geom_rootedge(rootedge = NULL, ...)

Arguments

ArgumentDescription
rootedgelength of rootedge; use phylo$root.edge if rootedge = NULL (by default).
...additional parameters

Value

ggplot layer

Author

Guangchuang Yu

Link to this function

geom_rootpoint()

geom_rootpoint

Description

add root point

Usage

geom_rootpoint(mapping = NULL, data = NULL, position = "identity",
  na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ...)

Arguments

ArgumentDescription
mappingaes mapping
datadata
positionposition
na.rmlogical
show.legendlogical
inherit.aeslogical
...addktional parameter

Value

root point layer

Author

Guangchuang Yu

Link to this function

geom_segment2()

geom_segment2

Description

geom_segment2 support aes(subset) via setup_data

Usage

geom_segment2(mapping = NULL, data = NULL, stat = "identity",
  position = "identity", lineend = "butt", na.rm = FALSE,
  show.legend = NA, inherit.aes = TRUE, nudge_x = 0, arrow = NULL,
  arrow.fill = NULL, ...)

Arguments

ArgumentDescription
mappingaes mapping
datadata
statName of stat to modify data
positionposition
lineendlineend
na.rmlogical
show.legendlogical
inherit.aeslogical
nudge_xhorizontal adjustment of x
arrowspecification for arrow heads, as created by arrow().
arrow.fillfill color to usse for the arrow head (if closed). NULL means use colour aesthetic.
...additional parameter

Value

add segment layer

Seealso

geom_segment

Author

Guangchuang Yu

geom_strip

Description

annotate associated taxa (from taxa1 to taxa2, can be Monophyletic, Polyphyletic or Paraphyletc Taxa) with bar and (optional) text label

Usage

geom_strip(taxa1, taxa2, label = NA, offset = 0, offset.text = 0,
  align = TRUE, barsize = 0.5, extend = 0, fontsize = 3.88,
  angle = 0, geom = "text", hjust = 0, fill = NA,
  family = "sans", parse = FALSE, ...)

Arguments

ArgumentDescription
taxa1taxa1
taxa2taxa2
labeloptional label
offsetoffset of bar and text from the clade
offset.textoffset of text from bar
alignlogical
barsizesize of bar
extendextend bar vertically
fontsizesize of text
angleangle of text
geomone of 'text' or 'label'
hjusthjust
fillfill label background, only work with geom='label'
familysans by default, can be any supported font
parselogical, whether parse label
...additional parameter

Value

ggplot layers

Author

Guangchuang Yu

Link to this function

geom_taxalink()

geom_taxalink

Description

link between taxa

Usage

geom_taxalink(taxa1, taxa2, curvature = 0.5, arrow = NULL,
  arrow.fill = NULL, ...)

Arguments

ArgumentDescription
taxa1taxa1, can be label or node number
taxa2taxa2, can be label or node number
curvatureA numeric value giving the amount of curvature. Negative values produce left-hand curves, positive values produce right-hand curves, and zero produces a straight line.
arrowspecification for arrow heads, as created by arrow().
arrow.fillfill color to usse for the arrow head (if closed). NULL means use colour aesthetic.
...additional parameter

Value

ggplot layer

Author

Guangchuang Yu

geom_text2

Description

geom_text2 support aes(subset) via setup_data

Usage

geom_text2(mapping = NULL, data = NULL, ..., stat = "identity",
  position = "identity", family = "sans", parse = FALSE,
  na.rm = TRUE, show.legend = NA, inherit.aes = TRUE, nudge_x = 0,
  nudge_y = 0, check_overlap = FALSE)

Arguments

ArgumentDescription
mappingthe aesthetic mapping
dataA layer specific dataset - only needed if you want to override he plot defaults.
...other arguments passed on to 'layer'
statName of stat to modify data
positionThe position adjustment to use for overlapping points on this layer
familysans by default, can be any supported font
parseif TRUE, the labels will be passd into expressions
na.rmlogical
show.legendlogical
inherit.aeslogical
nudge_xhorizontal adjustment
nudge_yvertical adjustment
check_overlapif TRUE, text that overlaps previous text in the same layer will not be plotted

Value

text layer

Seealso

geom_text

Author

Guangchuang Yu

geom_tiplab

Description

add tip label layer

Usage

geom_tiplab(mapping = NULL, hjust = 0, align = FALSE,
  linetype = "dotted", linesize = 0.5, geom = "text", offset = 0,
  ...)

Arguments

ArgumentDescription
mappingaes mapping
hjusthorizontal adjustment
alignalign tip lab or not, logical
linetypelinetype for adding line if align = TRUE
linesizeline size of line if align = TRUE
geomone of 'text', 'label', 'image' and 'phylopic'
offsettiplab offset
...additional parameter

Value

tip label layer

Author

Guangchuang Yu

Examples

require(ape)
tr <- rtree(10)
ggtree(tr) + geom_tiplab()

geom_tiplab2

Description

add tip label for circular layout

Usage

geom_tiplab2(mapping = NULL, hjust = 0, ...)

Arguments

ArgumentDescription
mappingaes mapping
hjusthorizontal adjustment
...additional parameter, see geom_tiplab

Value

tip label layer

Author

Guangchuang Yu

References

https://groups.google.com/forum/#!topic/bioc-ggtree/o35PV3iHO-0

Link to this function

geom_tippoint()

geom_tippoint

Description

add tip point

Usage

geom_tippoint(mapping = NULL, data = NULL, position = "identity",
  na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ...)

Arguments

ArgumentDescription
mappingaes mapping
datadata
positionposition
na.rmlogical
show.legendlogical
inherit.aeslogical
...addktional parameter

Value

tip point layer

Author

Guangchuang Yu

geom_tree

Description

add tree layer

Usage

geom_tree(mapping = NULL, data = NULL, layout = "rectangular",
  multiPhylo = FALSE, ...)

Arguments

ArgumentDescription
mappingaesthetic mapping
datadata
layoutone of 'rectangular', 'slanted', 'fan', 'circular', 'radial', 'equal_angle' or 'daylight'
multiPhylological
...additional parameter

Value

tree layer

Author

Yu Guangchuang

geom_tree2

Description

add tree layer

Usage

geom_tree2(layout = "rectangular", ...)

Arguments

ArgumentDescription
layoutone of 'rectangular', 'slanted', 'circular', 'radial' or 'unrooted'
...additional parameter

Value

tree layer

Author

Yu Guangchuang

Link to this function

geom_treescale()

geom_treescale

Description

add tree scale

Usage

geom_treescale(x = NULL, y = NULL, width = NULL, offset = NULL,
  color = "black", linesize = 0.5, fontsize = 3.88,
  family = "sans")

Arguments

ArgumentDescription
xx position
yy position
widthwidth of scale
offsetoffset of text to line
colorcolor
linesizesize of line
fontsizesize of text
familysans by default, can be any supported font

Value

ggplot layers

Author

Guangchuang Yu

Link to this function

getNodeAngledf()

getNodeAngle.df

Description

Get the angle between the two nodes specified.

Usage

getNodeAngle.df(df, origin_node_id, node_id)

Arguments

ArgumentDescription
dftree data.frame
origin_node_idorigin node id number
node_idend node id number

Value

angle in range [-1, 1], i.e. degrees/180, radians/pi

Link to this function

getNodesBreadthFirstdf()

getNodesBreadthFirst.df

Description

Get the nodes of tree from root in breadth-first order.

Usage

getNodesBreadthFirst.df(df)

Arguments

ArgumentDescription
dftree data.frame

Value

list of node id's in breadth-first order.

getSubtree

Description

Get all children of node from tree, including start_node.

Usage

getSubtree(tree, node)

Arguments

ArgumentDescription
treeape phylo tree object
nodeis the tree node id from which the tree is derived.

Value

list of all child node id's from starting node.

Link to this function

getSubtreeUnrooted()

getSubtreeUnrooted

Description

Get all subtrees of specified node. This includes all ancestors and relatives of node and return named list of subtrees.

Usage

getSubtreeUnrooted(tree, node)

Arguments

ArgumentDescription
treeape phylo tree object
nodeis the tree node id from which the subtrees are derived.

Value

named list of subtrees with the root id of subtree and list of node id's making up subtree.

Link to this function

getSubtreeUnrooteddf()

getSubtreeUnrooted

Description

Get all subtrees of node, as well as remaining branches of parent (ie, rest of tree structure as subtree) return named list of subtrees with list name as starting node id.

Usage

getSubtreeUnrooted.df(df, node)

Arguments

ArgumentDescription
dftree data.frame
nodeis the tree node id from which the subtrees are derived.

Value

named list of subtrees with the root id of subtree and list of node id's making up subtree.

getSubtree.df

Description

Get all children of node from df tree using breath-first.

Usage

getSubtree.df(df, node)

Arguments

ArgumentDescription
dftree data.frame
nodeid of starting node.

Value

list of all child node id's from starting node.

Link to this function

getTreeArcAngles()

getTreeArcAngles

Description

Find the right (clockwise rotation, angle from +ve x-axis to furthest subtree nodes) and left (anti-clockwise angle from +ve x-axis to subtree) Returning arc angle in [0, 2] (0 to 360) domain.

Usage

getTreeArcAngles(df, origin_id, subtree)

Arguments

ArgumentDescription
dftree data.frame
origin_idnode id from which to calculate left and right hand angles of subtree.
subtreenamed list of root id of subtree (node) and list of node ids for given subtree (subtree).

Value

named list with right and left angles in range [0,2] i.e 1 = 180 degrees, 1.5 = 270 degrees.

Link to this function

get_balance_position()

get_balance_position

Description

get position of balance (xmin, xmax, ymin, ymax)

Usage

get_balance_position(treeview, node, direction)

Arguments

ArgumentDescription
treeviewtree view
nodeselected node
directioneither (1 for 'up' or 2 for 'down')

Value

data.frame

Author

Justin Silverman

Link to this function

get_clade_position()

get_clade_position

Description

get position of clade (xmin, xmax, ymin, ymax)

Usage

get_clade_position(treeview, node)

Arguments

ArgumentDescription
treeviewtree view
nodeselected node

Value

data.frame

Author

Guangchuang Yu

Link to this function

get_heatmap_column_position()

get_heatmap_column_position

Description

return a data.frame that contains position information for labeling column names of heatmap produced by gheatmap function

Usage

get_heatmap_column_position(treeview, by = "bottom")

Arguments

ArgumentDescription
treeviewoutput of gheatmap
byone of 'bottom' or 'top'

Value

data.frame

Author

Guangchuang Yu

Link to this function

get_taxa_name()

get_taxa_name

Description

get taxa name of a selected node (or tree if node=NULL) sorted by their position in plotting

Usage

get_taxa_name(tree_view = NULL, node = NULL)

Arguments

ArgumentDescription
tree_viewtree view
nodenode

Value

taxa name vector

Author

Guangchuang Yu

get.path

Description

path from start node to end node

Usage

get.path(phylo, from, to)

Arguments

ArgumentDescription
phylophylo object
fromstart node
toend node

Value

node vectot

Author

Guangchuang Yu

visualizing phylogenetic tree and heterogenous associated data based on grammar of graphics ggtree provides functions for visualizing phylogenetic tree and its associated data in R.

Description

If you use ggtree in published research, please cite: Guangchuang Yu, David Smith, Huachen Zhu, Yi Guan, Tommy Tsan-Yuk Lam. ggtree: an R package for visualization and annotation of phylogenetic trees with their covariates and other associated data. Methods in Ecology and Evolution 2017, 8(1):28-36, doi:10.1111/2041-210X.12628

drawing phylogenetic tree from phylo object

Usage

ggtree(tr, mapping = NULL, layout = "rectangular", open.angle = 0,
  mrsd = NULL, as.Date = FALSE, yscale = "none",
  yscale_mapping = NULL, ladderize = TRUE, right = FALSE,
  branch.length = "branch.length", ...)

Arguments

ArgumentDescription
trphylo object
mappingaesthetic mapping
layoutone of 'rectangular', 'slanted', 'fan', 'circular', 'radial', 'equal_angle' or 'daylight'
open.angleopen angle, only for 'fan' layout
mrsdmost recent sampling date
as.Datelogical whether using Date class in time tree
yscaley scale
yscale_mappingyscale mapping for category variable
ladderizelogical (default TRUE ). Should the tree be re-organized to have a 'ladder' aspect?
rightlogical. If ladderize = TRUE , should the ladder have the smallest clade on the right-hand side? See ladderize for more information.
branch.lengthvariable for scaling branch, if 'none' draw cladogram
...additional parameter

Value

tree

Seealso

ladderize

Author

Yu Guangchuang

Examples

require(ape)
tr <- rtree(10)
ggtree(tr)
Link to this function

ggtree_ggproto()

StatBalance

Description

StatBalance

StatHilight

GeomHilight

gheatmap

Description

append a heatmap of a matrix to right side of phylogenetic tree

Usage

gheatmap(p, data, offset = 0, width = 1, low = "green",
  high = "red", color = "white", colnames = TRUE,
  colnames_position = "bottom", colnames_angle = 0,
  colnames_level = NULL, colnames_offset_x = 0,
  colnames_offset_y = 0, font.size = 4, hjust = 0.5)

Arguments

ArgumentDescription
ptree view
datamatrix or data.frame
offsetoffset of heatmap to tree
widthtotal width of heatmap, compare to width of tree
lowcolor of lowest value
highcolor of highest value
colorcolor of heatmap cell border
colnameslogical, add matrix colnames or not
colnames_positionone of 'bottom' or 'top'
colnames_angleangle of column names
colnames_levellevels of colnames
colnames_offset_xx offset for column names
colnames_offset_yy offset for column names
font.sizefont size of matrix colnames
hjusthjust for column names (0: align left, 0.5: align center, 1: align righ)

Value

tree view

Author

Guangchuang Yu

Link to this function

gzoom_methods()

gzoom method

Description

gzoom method

gzoom method

zoom selected subtree

Usage

gzoom(object, focus, subtree = FALSE, widths = c(0.3, 0.7), ...)
list(list("gzoom"), list("ggtree"))(object, focus, widths = c(0.3, 0.7),
  xmax_adjust = 0)
list(list("gzoom"), list("treedata"))(object, focus, subtree = FALSE,
  widths = c(0.3, 0.7))
list(list("gzoom"), list("phylo"))(object, focus, subtree = FALSE, widths = c(0.3,
  0.7))

Arguments

ArgumentDescription
objectsupported tree objects
focusselected tips
subtreelogical
widthswidths
...additional parameter
xmax_adjustadjust xmax (xlim[2])

Value

figure

gzoom

Description

plots simultaneously a whole phylogenetic tree and a portion of it.

Usage

gzoom.phylo(phy, focus, subtree = FALSE, widths = c(0.3, 0.7))

Arguments

ArgumentDescription
phyphylo object
focusselected tips
subtreelogical
widthswidths

Value

a list of ggplot object

Author

ygc

Examples

require(ape)
data(chiroptera)
gzoom(chiroptera, grep("Plecotus", chiroptera$tip.label))

identify

Description

identify node by interactive click

Usage

list(list("identify"), list("gg"))(x, ...)

Arguments

ArgumentDescription
xtree view
...additional parameters

Value

node id

Author

Guangchuang Yu

inset

Description

add insets in a tree

Usage

inset(tree_view, insets, width, height, hjust = 0, vjust = 0,
  x = "node", reverse_x = FALSE, reverse_y = FALSE)

Arguments

ArgumentDescription
tree_viewtree view
insetsa list of ggplot objects, named by node number
widthwidth of inset
heightheight of inset
hjusthorizontal adjustment
vjustvertical adjustment
xx position, one of 'node' and 'branch'
reverse_xwhether x axis was reversed by scale_x_reverse
reverse_ywhether y axis was reversed by scale_y_reverse

Value

tree view with insets

Author

Guangchuang Yu

Link to this function

layoutDaylight()

Equal daylight layout method for unrooted trees.

Description

#' @title

Usage

layoutDaylight(model, branch.length, MAX_COUNT = 5)

Arguments

ArgumentDescription
modeltree object, e.g. phylo or treedata
branch.lengthset to 'none' for edge length of 1. Otherwise the phylogenetic tree edge length is used.
MAX_COUNTthe maximum number of iterations to run (default 5)

Value

tree as data.frame with equal angle layout.

References

The following aglorithm aims to implement the vague description of the "Equal-daylight Algorithm" in "Inferring Phylogenies" pp 582-584 by Joseph Felsenstein.

 Leafs are subtrees with no children
 Initialise tree using equal angle algorithm
 tree_df = equal_angle(tree)
 
 nodes = get list of nodes in tree_df breadth-first
 nodes = remove tip nodes.
 
Link to this function

layoutEqualAngle()

layoutEqualAngle

Description

'Equal-angle layout algorithm for unrooted trees'

Usage

layoutEqualAngle(model, branch.length)

Arguments

ArgumentDescription
modeltree object, e.g. phylo or treedata
branch.lengthset to 'none' for edge length of 1. Otherwise the phylogenetic tree edge length is used.

Value

tree as data.frame with equal angle layout.

References

"Inferring Phylogenies" by Joseph Felsenstein.

msaplot

Description

multiple sequence alignment with phylogenetic tree

Usage

msaplot(p, fasta, offset = 0, width = 1, color = NULL,
  window = NULL, bg_line = TRUE, height = 0.8)

Arguments

ArgumentDescription
ptree view
fastafasta file, multiple sequence alignment
offsetoffset of MSA to tree
widthtotal width of alignment, compare to width of tree
colorcolor
windowspecific a slice to display
bg_linewhether add background line in alignment
heightheight ratio of sequence

Value

tree view

Author

Guangchuang Yu

multiplot

Description

plot multiple ggplot objects in one page

Usage

multiplot(..., plotlist = NULL, ncol, widths = rep_len(1, ncol),
  labels = NULL, label_size = 5)

Arguments

ArgumentDescription
...plots
plotlistplot list
ncolnumber of column
widthswidths of plots
labelslabels for labeling the plots
label_sizefont size of label

Value

plot

Author

Guangchuang Yu

nodebar

Description

generate a list of bar charts for results of ancestral state reconstruction

Usage

nodebar(data, cols, color, alpha = 1, position = "stack")

Arguments

ArgumentDescription
dataa data.frame of stats with an additional column of node number
colscolumn of stats
colorcolor of bar
alphaalpha
positionposition of bar, one of 'stack' and 'dodge'

Value

list of ggplot objects

Author

Guangchuang Yu

nodeid

Description

convert tip or node label(s) to internal node number

Usage

nodeid(x, label)

Arguments

ArgumentDescription
xtree object or graphic object return by ggtree
labeltip or node label(s)

Value

internal node number

Author

Guangchuang Yu

nodepie

Description

generate a list of pie charts for results of ancestral stat reconstruction

Usage

nodepie(data, cols, color, alpha = 1)

Arguments

ArgumentDescription
dataa data.frame of stats with an additional column of node number
colscolumn of stats
colorcolor of bar
alphaalpha

Value

list of ggplot objects

Author

Guangchuang Yu

open_tree

Description

open tree with specific angle

Usage

open_tree(treeview, angle)

Arguments

ArgumentDescription
treeviewtree view
angleangle

Value

updated tree view

Author

Guangchuang Yu

phylopic

Description

add phylopic layer

Usage

phylopic(tree_view, phylopic_id, size = 512, color = "black",
  alpha = 0.5, node = NULL, x = NULL, y = NULL, width = 0.1)

Arguments

ArgumentDescription
tree_viewtree view
phylopic_idphylopic id
sizesize of phylopic to download
colorcolor
alphaalpha
nodeselected node
xx position
yy position
widthwidth of phylopic

Value

phylopic layer

Author

Guangchuang Yu

range_format

Description

format a list of range (HPD, CI, etc that has length of 2)

Usage

range_format(x, trans = NULL)

Arguments

ArgumentDescription
xinput list
transtransformation function

Value

character vector of '[lower, upper]'

Author

Guangchuang Yu

Objects exported from other packages

Description

These objects are imported from other packages. Follow the links below to see their documentation.

list(" ", " ", list(list("ape"), list(list(list("rtree")), ", ", list(list("read.tree")), ", ", list(list("read.nexus")))), " ", " ", " ", list(list("dplyr"), list(list(list("collapse")))), " ", " ", " ", list(list("ggplot2"), list(list(list("fortify")), ", ", list(list("ggplot")), ", ", list(list("xlim")), ", ", list(list("theme")), ", ", list(list("ggsave")), ", ", list(list("aes")), ", ", list(list("fortify")), ", ", list(list("geom_text")), ", ", list(list("geom_label")), ", ", list(list(

"geom_point")))), "

", " ", " ", list(list("magrittr"), list(list(list("%>%")))), " ", " ", " ", list(list("tidytree"), list(list(list("groupOTU")), ", ", list(list("groupClade")))), " ", " ", " ", list(list("treeio"), list(list(list("read.astral")), ", ", list(list("read.beast")), ", ", list(list("read.codeml")), ", ", list(list("read.codeml_mlc")), ", ", list(list("read.hyphy")), ", ", list(list("read.iqtree")), ", ", list(list("read.jplace")), ", ", list(list("read.jtree")), ", ",

list(list("read.mrbayes")), ", ", list(list("read.newick")), ", ", list(list("read.nhx")), ", ", list(list("read.paml_rst")), ", ", list(list("read.phylip")), ", ", list(list("read.phyloT")), ", ", list(list("read.r8s")), ", ", list(list("read.raxml")))), "

")

revts

Description

reverse timescle x-axis

Usage

revts(treeview)

Arguments

ArgumentDescription
treeviewtreeview

Value

updated treeview

Author

guangchuang yu

rotate

Description

rotate 180 degree of a selected branch

Usage

rotate(tree_view = NULL, node)

Arguments

ArgumentDescription
tree_viewtree view
nodeselected node

Value

ggplot2 object

Author

Guangchuang Yu

Link to this function

rotateTreePointsdf()

rotateTreePoints.data.fram

Description

Rotate the points in a tree data.frame around a pivot node by the angle specified.

Usage

rotateTreePoints.df(df, pivot_node, nodes, angle)

Arguments

ArgumentDescription
dftree data.frame
pivot_nodeis the id of the pivot node.
nodeslist of node numbers that are to be rotated by angle around the pivot_node
anglein range [0,2], ie degrees/180, radians/pi

Value

updated tree data.frame with points rotated by angle

rotate_tree

Description

rotate circular tree

Usage

rotate_tree(treeview, angle)

Arguments

ArgumentDescription
treeviewtree view
angleangle

Value

updated tree view

Author

Guangchuang Yu

scaleClade

Description

scale clade

Usage

scaleClade(tree_view = NULL, node, scale = 1, vertical_only = TRUE)

Arguments

ArgumentDescription
tree_viewtree view
nodeclade node
scalescale
vertical_onlylogical. If TRUE, only vertical will be scaled. If FALSE, the clade will be scaled vertical and horizontally. TRUE by default.

Value

tree view

Author

Guangchuang Yu

Link to this function

scale_color_methods()

scale_color method

Description

scale_color method

scale color by a numerical tree attribute

Usage

scale_color(object, by, ...)
list(list("scale_color"), list("treedata"))(object, by, ...)
list(list("scale_color"), list("phylo"))(object, by, ...)

Arguments

ArgumentDescription
objecttreedata object
byone of numerical attributes
...additional parameter

Value

color vector

Link to this function

scale_x_ggtree()

scale_x_ggtree

Description

scale x for tree with heatmap

Usage

scale_x_ggtree(tree_view, breaks = NULL, labels = NULL)

Arguments

ArgumentDescription
tree_viewtree view
breaksbreaks for tree
labelslables for corresponding breaks

Value

tree view

Author

Guangchuang Yu

Link to this function

set_hilight_legend()

set_hilight_legend

Description

set legend for multiple geom_hilight layers

Usage

set_hilight_legend(p, color, label, alpha = 1)

Arguments

ArgumentDescription
pggtree object
colorcolor vector
labellabel vector
alphatransparency of color

Value

updated ggtree object

Author

Guangchuang Yu

stat_balance

Description

stat_balance

Usage

stat_balance(mapping = NULL, data = NULL, geom = "rect",
  position = "identity", node, show.legend = NA, inherit.aes = FALSE,
  fill, color, alpha, extend = 0, extendto = NULL, ...)

Arguments

ArgumentDescription
mappingaes mapping
datadata
geomgeometric object
positionposition
nodenode number
show.legendshow legend
inherit.aeslogical
fillfill color
colorcolor to outline highlights and divide balance
alphatransparency
extendextend xmax of the rectangle
extendtoextend xmax to extendto
...additional parameter

Value

layer

stat_hilight

Description

stat_hilight

Usage

stat_hilight(mapping = NULL, data = NULL, geom = "rect",
  position = "identity", node, show.legend = NA, inherit.aes = FALSE,
  fill, alpha, extend = 0, extendto = NULL, ...)

Arguments

ArgumentDescription
mappingaes mapping
datadata
geomgeometric object
positionposition
nodenode number
show.legendshow legend
inherit.aeslogical
fillfill color
alphatransparency
extendextend xmax of the rectangle
extendtoextend xmax to extendto
...additional parameter

Value

layer

subview

Description

add subview to mainview for ggplot2 objects

Usage

subview(mainview, subview, x, y, width = 0.1, height = 0.1)

Arguments

ArgumentDescription
mainviewmain view
subviewa ggplot or grob object
xx position
yy position
widthwidth of subview, [0,1]
heightheight of subview, [0,1]

Value

ggplot object

Author

Guangchuang Yu

theme_inset

Description

inset theme

Usage

theme_inset(...)

Arguments

ArgumentDescription
...additional parameter

Details

theme for inset function

Value

ggplot object

Author

Guangchuang Yu

theme_tree

Description

tree theme

Usage

theme_tree(bgcolor = "white", fgcolor = "black", ...)

Arguments

ArgumentDescription
bgcolorbackground color
fgcolorforeground color
...additional parameter

Value

updated ggplot object with new theme

Author

Yu Guangchuang

Examples

require(ape)
tr <- rtree(10)
ggtree(tr) + theme_tree()

theme_tree2

Description

tree2 theme

Usage

theme_tree2(bgcolor = "white", fgcolor = "black", ...)

Arguments

ArgumentDescription
bgcolorbackground color
fgcolorforeground color
...additional parameter

Value

updated ggplot object with new theme

Author

Yu Guangchuang

Examples

require(ape)
tr <- rtree(10)
ggtree(tr) + theme_tree2()

%<%

Description

update tree

Usage

pg %<% x

Arguments

ArgumentDescription
pgggplot2 object
xupdate by x

Value

updated ggplot object

Author

Guangchuang Yu

Examples

library("ggplot2")
nwk <- system.file("extdata", "sample.nwk", package="treeio")
tree <- read.tree(nwk)
p <- ggtree(tree) + geom_tippoint(color="#b5e521", alpha=1/4, size=10)
p %<% rtree(30)

viewClade

Description

view a clade of tree

Usage

viewClade(tree_view = NULL, node, xmax_adjust = 0)

Arguments

ArgumentDescription
tree_viewfull tree view
nodeinternal node number
xmax_adjustadjust xmax

Value

clade plot

Author

Guangchuang Yu

xlim_expand

Description

expand x axis limits for specific panel

Usage

xlim_expand(xlim, panel)

Arguments

ArgumentDescription
xlimxlim
panelpanel

Value

updated tree view

Author

guangchuang yu

xlim_tree

Description

set x axis limits for Tree panel

Usage

xlim_tree(xlim)

Arguments

ArgumentDescription
xlimxlim

Value

updated tree view

Author

guangchuang yu