Friday, May 29, 2020

Vectorize add.arrow

I just vectorized add.arrow. This means that more than one arrow can be added to a your plotted tree at a time - although these arrows must be of the same color.

Here's how it works:

library(phytools)
data(anoletree)
par(bg="#f2f2f2")
plotTree(anoletree,type="fan",fsize=0.7)
add.arrow(anoletree,tip=c("Anolis_cuvieri","Anolis_krugi",
    "Anolis_pulchellus","Anolis_poncensis","Anolis_stratulus",
    "Anolis_evermanni","Anolis_cooki","Anolis_cristatellus",
    "Anolis_gundlachi","Anolis_occultus"),lwd=6,arrl=1)
add.arrow(anoletree,tip="Anolis_cuvieri",col="green",
    lwd=4,arrl=1)
add.arrow(anoletree,tip=c("Anolis_krugi","Anolis_pulchellus",
    "Anolis_poncensis"),col="#E4D96F",lwd=4,arrl=1)
add.arrow(anoletree,tip=c("Anolis_stratulus","Anolis_evermanni"),
    col="darkgreen",lwd=4,arrl=1)
add.arrow(anoletree,tip=c("Anolis_cooki","Anolis_cristatellus",
    "Anolis_gundlachi"),col="brown",lwd=4,arrl=1)
add.arrow(anoletree,tip="Anolis_occultus",col="darkgrey",
    lwd=4,arrl=1)
legend(x="topleft",c("crown-giant","grass-bush","trunk-crown","trunk-ground",
    "twig"),pch=22,pt.bg=c("green","#E4D96F","darkgreen",
    "brown","darkgrey"),cex=0.9,
    pt.cex=2,title="PR ecomorphs",bty="n")

plot of chunk unnamed-chunk-1

That's it.

No comments:

Post a Comment

Note: due to the very large amount of spam, all comments are now automatically submitted for moderation.