Created
February 22, 2024 08:56
-
-
Save dill/55c297d74857d6f484a7e2cc646883c7 to your computer and use it in GitHub Desktop.
random phylogenetic trees + multidimensional scaling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) | |
} |
Author
dill
commented
Feb 22, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment