Package 'ggtreeSpace'

Title: Visualizing Phylomorphospaces using 'ggtree'
Description: This package is a comprehensive visualization tool specifically designed for exploring phylomorphospace. It not only simplifies the process of generating phylomorphospace, but also enhances it with the capability to add graphic layers to the plot with grammar of graphics to create fully annotated phylomorphospaces. It also provide some utilities to help interpret evolutionary patterns.
Authors: Guangchuang Yu [aut, cre, ths, cph] , Li Lin [ctb]
Maintainer: Guangchuang Yu <[email protected]>
License: Artistic-2.0
Version: 1.1.1
Built: 2024-10-07 03:25:14 UTC
Source: https://github.com/bioc/ggtreeSpace

Help Index


A layer of phylomorphospace

Description

A layer of phylomorphospace

Usage

geom_treespace(tr, data, mapping = NULL, ...)

Arguments

tr

a tree object. This should be an object of class that is compatible with 'ggtree', typically an object of class 'phylo' or 'treedata'.

data

Trait data as a data frame or matrix, where each row represents a tree tip or node.

For data matching the number of tips, ancestral traits are reconstructed for internal nodes.

For data equal to the total number of nodes, values are directly used as node coordinates.

mapping

aesthetic mapping

...

additional parameters for customization with 'geom_tree'. Please use '?ggtree::geom_tree' for more information.

Value

ggplot object

Examples

library(ggplot2)
library(ggtree)
library(phytools)

tr <- rtree(10)
a <- fastBM(tr, nsim = 2)

p <- ggplot() +
    geom_treespace(tr, a)

Add a layer of heat map with trait data

Description

Add a layer of heat map with trait data

Usage

geom_tsheatmap(trait, resolution = 0.001, bins = 24, ...)

Arguments

trait

trait data. It can be either a data frame with node numbers and trait, or a trait name present in the plot data.

resolution

resolution of the heat map

bins

number of contour bins

...

additional parameters for 'geom_contour_filled'. Please use '?ggplot2::geom_contour_filled' for more information.

Value

ggplot object

Examples

library(ggtree)
library(phytools)
library(ggplot2)
library(ggtreeSpace)

tr <- rtree(15)
td <- fastBM(tr, nsim = 2, bounds = c(0, Inf))
col <- colorRampPalette(c(
    "#FFFFCC", "#FFEDA0", "#FED976", "#FEB24C",
    "#FD8D3C", "#FC4E2A", "#E31A1C", "#B10026"
))(24)
tdex <- data.frame(
    z = fastBM(tr, nsim = 1, bounds = c(0, Inf)),
    node = 1:15
)
p <- ggtreespace(tr, td)
p %<+% tdex +
    geom_tippoint() +
    geom_tsheatmap(trait = "z", alpha = 0.7, resolution = 0.01, bin = 24) +
    scale_fill_manual(
        values = col,
        guide = guide_colorsteps(show.limits = TRUE)
    ) +
    theme_treespace2() +
    theme(
        legend.key.height = unit(1, "null"),
        legend.justification.top = "right"
    )

Plot phylomorphospace

Description

This function plots a phylomorphospace by mapping a tree object onto a vector space like morphospace.

Usage

ggtreespace(tr, data, mapping = NULL, ...)

Arguments

tr

a tree object. This should be an object of class that is compatible with 'ggtree', typically an object of class 'phylo' or 'treedata'.

data

Trait data as a data frame or matrix, where each row represents a tree tip or node.

For data matching the number of tips, ancestral traits are reconstructed for internal nodes.

For data equal to the total number of nodes, values are directly used as node coordinates.

mapping

aesthetic mapping

...

additional parameters for customization with 'ggtree'. Please use '?ggtree::ggtree' for more information.

Value

ggtreeSpace object

Examples

library(ggtree)
library(phytools)
library(ggtreeSpace)

tr <- rtree(15)
td <- fastBM(tr, nsim = 2)
ggtreespace(tr, td) +
    geom_tippoint()

Make plot data for ggtreespace. This function processes a phylogenetic tree and associated trait data to create a data frame suitable for plotting with 'ggtreespace'.

Description

Make plot data for ggtreespace. This function processes a phylogenetic tree and associated trait data to create a data frame suitable for plotting with 'ggtreespace'.

Usage

make_ts_data(tr, data)

Arguments

tr

a tree object. This should be an object of class that is compatible with 'ggtree', typically an object of class 'phylo' or 'treedata'.

data

Trait data as a data frame or matrix, where each row represents a tree tip or node.

For data matching the number of tips, ancestral traits are reconstructed for internal nodes.

For data equal to the total number of nodes, values are directly used as node coordinates.

Value

ggplot object

Examples

library(ggplot2)
library(ggtree)
library(phytools)

tr <- rtree(10)
a <- fastBM(tr, nsim = 2)

trd <- make_ts_data(tr, a)

Plot phylogenetic scatterplot matrix.

Description

This function creates a scatterplot matrix for comparing multiple continuous traits mapped onto the same phylogenetic tree, providing a visual representation of trait correlations and evolutionary patterns.

Usage

phylospm(
tr,
traits = NULL,
title = NULL,
xAxisLabels = NULL,
yAxisLabels = NULL,
tr.params = list(size = 1, colors = NULL, panel.grid = TRUE),
sptr.params = list(tippoint = TRUE, tiplab = FALSE, labdir = "horizonal",
                    panel.grid = TRUE)
)

Arguments

tr

A phylogenetic tree

traits

A data frame containing multiple column of trait data

title

Set the title for the phylogenetic scatterplot matrix

xAxisLabels

Set the label of the x axis

yAxisLabels

Set the label of the y axis

tr.params

List of parameters to customize the phylogenetic tree with continuous trait mapping as continuous colors on the branch.

Users can add tip point, add tip label, set tip label direction and set background gird.

sptr.params

List of parameters to customize the phylomorphospaces. Users can add tip point, add tip label, set tip label direction and set background gird.

Value

phylospm object

Examples

library(ggtree)
library(phytools)
library(ggtreeSpace)

tr <- rtree(10)
a <- fastBM(tr, nsim = 4)

phylospm(tr, a)

Phylomorphospace theme No.1, with arrow-end axis and grey panel grid.

Description

Phylomorphospace theme No.1, with arrow-end axis and grey panel grid.

Usage

theme_treespace(...)

Arguments

...

additional parameters for 'ggplot2::theme'. Please use '?ggplot2::theme()' to learn more information.

Value

a theme object with arrow-end axis

Examples

library(ggtree)
library(phytools)
library(ggtreeSpace)

tr <- rtree(15)
td <- fastBM(tr, nsim = 2)
ggtreespace(tr, td) +
    geom_tippoint() +
    theme_treespace()

Phylomorphospace theme No.2, with blank background and panel border.

Description

Phylomorphospace theme No.2, with blank background and panel border.

Usage

theme_treespace2(...)

Arguments

...

additional parameters for 'ggplot2::theme'. Please use '?ggplot2::theme()' to learn more information.

Value

a theme object with blank background and panel border

Examples

library(ggtree)
library(phytools)
library(ggtreeSpace)

tr <- rtree(15)
td <- fastBM(tr, nsim = 2)
ggtreespace(tr, td) +
    geom_tippoint() +
    theme_treespace2()