Skip to content

Instantly share code, notes, and snippets.

@dill
Created February 22, 2024 08:56
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 dill/55c297d74857d6f484a7e2cc646883c7 to your computer and use it in GitHub Desktop.
Save dill/55c297d74857d6f484a7e2cc646883c7 to your computer and use it in GitHub Desktop.
random phylogenetic trees + multidimensional scaling
# generate a random phylogenetic tree, then apply multidimensional
# scaling to the distances and see what the 2D plot looks like
library(ape)
layout(matrix(1:12, 3, 4, byrow=TRUE))
for (i in 1:3){
# generate a tree
rr <- rtree(20)
# get distances between nodes
d <- cophenetic.phylo(rr)
# do an MDS
mds <- cmdscale(d, k=6)
# plot that beside the tree
plot(rr, main=i)
plot(mds[,1:2], main=i, type="n")
text(mds[,1:2], label=rr$tip.label)
plot(mds[,3:4], main=i, type="n")
text(mds[,3:4], label=rr$tip.label)
plot(mds[,5:6], main=i, type="n")
text(mds[,5:6], label=rr$tip.label)
}
@dill
Copy link
Author

dill commented Feb 22, 2024

Screenshot from 2024-02-22 08-53-52

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