Skip to content

Instantly share code, notes, and snippets.

@Rekyt
Created September 6, 2016 11:56
Show Gist options
  • Select an option

  • Save Rekyt/7e174173dad295ad4b54479d53245488 to your computer and use it in GitHub Desktop.

Select an option

Save Rekyt/7e174173dad295ad4b54479d53245488 to your computer and use it in GitHub Desktop.
plot trait values at the tip of phylogeny
# Script to add a trait matrix over a circular phylogenetic tree
# Packages ---------------------------------------------------------------------
library(ape)
library(ggtree)
# Generate Tree and Traits -----------------------------------------------------
# Number of species
n_species = 200
# Generate tree with 10 species
random_tree = rtree(n_species)
# Generate trait matrix
trait_df = data.frame(
species = random_tree$tip.label,
trait1 = rnorm(n_species), # Example of continuous trait
# Example of categorical traits
trait2 = sample(c("A", "B", "C"), replace = T, size = n_species))
# Plotting tree ----------------------------------------------------------------
plot_tree = ggtree(random_tree, layout = "fan", right = TRUE, size = 0.1)
# Add trait information into tree
plot_tree %<+% trait_df + geom_tippoint(aes(color = trait1, alpha = 0.5))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment