Skip to content

Instantly share code, notes, and snippets.

@zkamvar
Created February 17, 2015 21:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zkamvar/5b60cccc117276604648 to your computer and use it in GitHub Desktop.
Save zkamvar/5b60cccc117276604648 to your computer and use it in GitHub Desktop.
plot_phylo
# Two functions to plot phylo objects from ape.
#
# Both of these functions plot their respective trees. The ... gives the user
# the ability to adjust things like color or font size.
#
nj_plot_phylo <- function(tree, ...){
barlen <- min(median(tree$edge.length), 0.1)
if (barlen < 0.1) barlen <- 0.01
tree <- ladderize(tree)
plot.phylo(tree, font = 2, adj = 0, xpd = TRUE,
label.offset = 0.0125, ...)
nodelabels(tree$node.label, adj = c(1.3, -0.5), frame = "n", cex = 0.8,
font = 3, xpd = TRUE)
add.scale.bar(lwd = 5, length = barlen)
}
upgma_plot_phylo <- function(tree, ...){
barlen <- min(median(tree$edge.length), 0.1)
if (barlen < 0.1) barlen <- 0.01
plot.phylo(tree, font = 2, adj = 0, xpd = TRUE,
label.offset = 0.0125, ...)
nodelabels(tree$node.label, adj = c(1.3, -0.5), frame = "n", cex = 0.8,
font = 3, xpd = TRUE)
axisPhylo(3)
}
@zkamvar
Copy link
Author

zkamvar commented Feb 17, 2015

usage:

devtools::source_gist("5b60cccc117276604648")
library(poppr)
# For small NJ trees
nj_plot_phylo(myNTree, cex = 0.8)
# For small UPGMA trees.
upgma_plot_phylo(myUTree, cex = 0.8)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment