## Friday, March 29, 2024

### Function for plotting discrete and/or continuous characters at the tips of a fan or arc-style tree (`plotFanTree.wTraits`) now in phytools

Over the past few days I’ve made various posts about graphing discretely & continuous-valued trait data at the tips of an “arc” or “fan” style tree (1, 2, 3).

After some fixes and improvements, my best solution to this problem (here) has now been added to the phytools package on GitHub (which can be installed, as always, using the remotes or devtools packages).

Here’s a quick example using a now classic phylogeny & trait dataset for Anolis lizards from Mahler et al. (2010).

``````library(phytools)
packageVersion("phytools")
``````
``````## [1] '2.2.2'
``````
``````data(anoletree)
anoletree
``````
``````##
## Phylogenetic tree with 82 tips and 81 internal nodes.
##
## Tip labels:
## 	ahli, allogus, rubribarbus, imias, sagrei, bremeri, ...
##
## The tree includes a mapped, 6-state discrete character
## with states:
## 	CG, GB, TC, TG, Tr, Tw
##
## Rooted; includes branch lengths.
``````
``````data(anole.data)
``````
``````anole_resid<-phyl.resid(anoletree,
x=setNames(anole.data[,"SVL"],rownames(anole.data)),
Y=anole.data[,2:6])
cbind(anole.data[,1,drop=FALSE],anole_resid\$resid),
part=0.5,arc_height=1,spacer=0.1,fsize=0.7)
h<-max(nodeHeights(anoletree))
arc_height<-1
text(x=h+seq(0.05,by=0.07,length.out=ncol(anole.data))*h+
arc_height*h,y=rep(-0.5,ncol(anole.data)),
c("SVL",paste("resid(",colnames(anole.data)[2:6],")",sep="")),
text(x=-h-seq(0.05,by=0.07,length.out=ncol(anole.data))*h-
arc_height*h,y=rep(-0.5,ncol(anole.data)),
c("SVL",paste("resid(",colnames(anole.data)[2:6],")",sep="")),
subtitle="",x=-0.75*h,y=0,prompt=FALSE,outline=FALSE,
lwd=8)
``````tree<-rtree(n=200)