Skip to content

Instantly share code, notes, and snippets.

@ms609
Created June 2, 2022 08:26
Show Gist options
  • Select an option

  • Save ms609/ba78b1dd41aa8f2fd7f25d415588e18f to your computer and use it in GitHub Desktop.

Select an option

Save ms609/ba78b1dd41aa8f2fd7f25d415588e18f to your computer and use it in GitHub Desktop.

Revisions

  1. ms609 renamed this gist Jun 2, 2022. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. ms609 created this gist Jun 2, 2022.
    13 changes: 13 additions & 0 deletions tree_on_plot.R
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@

    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")