Skip to content

Instantly share code, notes, and snippets.

@ms609
Created June 2, 2022 08:26
Show Gist options
  • Save ms609/ba78b1dd41aa8f2fd7f25d415588e18f to your computer and use it in GitHub Desktop.
Save ms609/ba78b1dd41aa8f2fd7f25d415588e18f to your computer and use it in GitHub Desktop.
Add phylogenetic tree to MDS plot of leaves in R
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