rphylogenyape

Phylogenetic tree ape too small


I am building a phylogenetic tree using data from NCBI taxonomy. The tree is quite simple, its aims is to show the relationship among a few Arthropods. The problem is the tree looks very small and I can't seem to make its branches longer. I would also like to color some nodes (Ex: Pancrustaceans) but I don't know how to do this using ape. Thanks for any help!

library(treeio)
library(ape)
treeText <- readLines('phyliptree.phy')
treeText <- paste0(treeText, collapse="")

tree <- read.tree(text = treeText) ## load tree 
distMat <- cophenetic(tree) ## generate dist matrix

plot(tree, use.edge.length = TRUE,show.node.label = T, edge.width = 2, label.offset = 0.75, type = "cladogram",  cex = 1, lwd=2)

enter image description here


Solution

  • Here are some pointers using the ape package. I am using a random tree as we don't have access to yours, but these examples should be easily adaptable to your problem. If your provide a reproducible example of a specific question, I could take another look.

    First me make a random tree, add some species names, and plot it to show the numbers of nodes (both terminal and internal)

    library(ape)
    set.seed(123)
    Tree <- rtree(10)
    Tree$tip.label <- paste("Species", 1:10, sep="_")
    plot.phylo(Tree)
    nodelabels() # blue
    tiplabels() # yellow
    edgelabels() # green
    

    enter image description here

    Then, to color any node or edge of the tree, we can create a vector of colors and provide it to the appropriate *labels() function.

    # using numbers for colors
    node_colors <- rep(5:6, each=5)[1:9] # 9 internal nodes 
    edge_colors <- rep(3:4, each=9) # 18 branches
    tip_colors <- rep(c(11,12,13), 4)
    # plot:
    plot.phylo(Tree, edge.color = edge_colors, tip.color = tip_colors) 
    nodelabels(pch = 21, bg = node_colors, cex=2)
    

    enter image description here

    To label just one node and the clade descending from it, we could do:

    Nnode(Tree)
    node_colors <- rep(NA, 9)
    node_colors[7] <- "green"
    node_shape <- ifelse(is.na(node_colors), NA, 21)
    edge_colors <- rep("black", 18)
    edge_colors[13:18] <- "green"
    plot(Tree, edge.color = edge_colors, edge.width = 2, label.offset = .1)
    nodelabels(pch=node_shape, bg=node_colors, cex=2)
    

    enter image description here

    Without your tree, it is harder to tell how to adjust the branches. One way is to reduce the size of the tip labels, so they take up less space. Another way might be to play around when saving the png or pdf.

    There are other ways of doing these embellishments of trees, including the ggtree package.