Created
June 2, 2022 08:26
-
-
Save ms609/ba78b1dd41aa8f2fd7f25d415588e18f to your computer and use it in GitHub Desktop.
Add phylogenetic tree to MDS plot of leaves in R
This file contains hidden or 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
poEdge <- Postorder(tree())$edge | |
parent <- poEdge[, 1] | |
child <- poEdge[, 2] | |
xy <- matrix(0, parent[1], 2) | |
xy[seq_len(NTip(tree())), ] <- mapping() | |
for (node in unique(parent)) { | |
xy[node, ] <- colMeans(xy[child[parent == node], , drop = FALSE]) | |
} | |
segments(xy[parent, 1], xy[parent, 2], | |
xy[child, 1], xy[child, 2], | |
col = "#00000033") | |
points(xy[parent, 1], xy[parent, 2], pch = ".", col = "#00000099") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment