Dear Rafa & list. Here is a solution: http://blog.phytools.org/2023/04/coloring-edges-of-plotted-tree-by.html.
I applied it to marginal ancestral states obtained using the new /phytools/ method /ancr/, but the same principle could be used with a summary of stochastic maps. I will make a subsequent follow-up post covering that. Let us know if this works! All the best, Liam Liam J. Revell Professor of Biology, University of Massachusetts Boston Web: http://faculty.umb.edu/liam.revell/ Book: Phylogenetic Comparative Methods in R <https://press.princeton.edu/books/phylogenetic-comparative-methods-in-r> (/Princeton University Press/, 2022) On 4/18/2023 1:21 PM, Liam J. Revell wrote: > > Dear Rafa. > > Just a quick comment re the comment "I also noticed that results of > simmap have one extra edge than the tree > itself...." > > From ancestral state reconstruction (marginal reconstruction or a > summary of stochastic mapping) you'll end up with a matrix containing > a number of rows equal to the number of internal nodes of the tree, or > (in your case) the number of tips + the number of internal nodes. In > your case, you're interested in coloring all the edges of the tree, > which will be one fewer than the number of nodes + tips. This is > because every node (or tip) is preceded by one edge: except for the > root. Likewise, the order of your ancestral state matrix is by node > index; whereas the edges of the tree can have a variety of different > orders. > > Let me post a solution to my blog quickly & then I'll share it with > this group. > > All the best, Liam > > Liam J. Revell > Professor of Biology, University of Massachusetts Boston > Web: http://faculty.umb.edu/liam.revell/ > Book: Phylogenetic Comparative Methods in R > <https://press.princeton.edu/books/phylogenetic-comparative-methods-in-r> > (/Princeton University Press/, 2022) > > > On 4/18/2023 10:59 AM, Rafael S Marcondes wrote: >> CAUTION: EXTERNAL SENDER >> >> Hi all, >> >> I would like to use the results of make.simmap to plot the edges of a tree >> by their most likely state. (Because my tree is really large and plotting >> pie charts at the nodes gets really polluted.) >> >> So first I took $ace from the results to describe.simmap and added a column >> for the most likely state, and another column for the color for plotting: >> >>> head(ace.max.lik) >> CL EL M P SL maxlik col >> 6621 0 0.000 0.002 0.998 0 P darkgoldenrod3 >> 6622 0 0.000 0.001 0.999 0 P darkgoldenrod3 >> 6623 0 0.000 0.007 0.993 0 P darkgoldenrod3 >> 6624 0 0.000 0.004 0.996 0 P darkgoldenrod3 >> 6625 0 0.000 0.001 0.999 0 P darkgoldenrod3 >> 6626 0 0.001 0.020 0.979 0 P darkgoldenrod3 >> >> And I separately did that for the tips. (Which I also estimated, since they >> had uncertainty in the original data): >> >> CL EL M P SL maxlik col >> Rhea_americana 0.000 0.000 0.000 1.000 >> 0.000 P darkgoldenrod3 >> Rhea_pennata 0.000 0.000 0.008 0.992 >> 0.000 P darkgoldenrod3 >> Casuarius_casuarius 0.000 0.004 0.074 0.922 >> 0.000 P darkgoldenrod3 >> Casuarius_bennetti 0.000 0.010 0.132 0.858 >> 0.000 P darkgoldenrod3 >> Dromaius_novaehollandiae 0.001 0.000 0.045 0.953 >> 0.001 P darkgoldenrod3 >> Apteryx_owenii 0.000 0.000 0.995 0.005 >> 0.000 M blue >> >> Then I tried to plot the edges by color using ape, putting the tips in >> front of the internal nodes because that's the typical order of tree$edges: >> >> plot.phylo(x=m.ard[[1]],cex=0.2,edge.width=0.01,type='fan', >> edge.lty=3,edge.color=c(tip.max.lik$col, ace.max.lik$col)) >> >> It plots a beautiful plot, by the colors are mismatched to the edges. I >> also noticed that results of simmap have one extra edge than the tree >> itself: >> >>> nrow(md.ard$ace) >> [1] 13239 >> >>> nrow(m.ard[[1]]$edge) >> [1] 13238 >> >> I suspect that's that one extra edge that's causing the mismatch, but I >> can't figure out where it's coming from, or how to fix it. Any tips or >> workarounds to accomplish this task, which I might be overcomplicating? >> >> PS: I'm well aware that it's a bad idea to "flatten" the likelihoods of >> different states into a single most likely state, and I absolutely do not >> plan to discard that uncertainty. I just want to plot a simpler tree for >> visualization. >> >> Thanks! >> >> -Rafa >> >> *--* >> *Rafael S. Marcondes, Ph.D.* >> *https://www.rafaelmarcondes.com/ <https://www.rafaelmarcondes.com/>* >> Faculty Fellow in EEB >> Department of BioSciences >> Rice University >> Houston TX 77005 >> >> Pronouns: he/him >> >> >> *"Eu quase que nada não sei. Mas desconfio de muita coisa"* >> *"I almost don't know nothing. But I suspect many things"* >> -João Guimarães Rosa, Brazilian novelist >> (Portuguese original and free English translation by me) >> >> [[alternative HTML version deleted]] >> >> _______________________________________________ >> R-sig-phylo mailing list -R-sig-phylo@r-project.org >> https://stat.ethz.ch/mailman/listinfo/r-sig-phylo >> Searchable archive athttp://www.mail-archive.com/r-sig-phylo@r-project.org/ [[alternative HTML version deleted]] _______________________________________________ R-sig-phylo mailing list - R-sig-phylo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-phylo Searchable archive at http://www.mail-archive.com/r-sig-phylo@r-project.org/