Hi,
I wrote a code some times ago to do this. It perhaps needs to be adapted.
Do not hesitate to ask if it is not clear.
library(ape)
#===FONCTION=
`edgeAttributes` -
function(node.values, tree, upstream=T){
# node.value must not be a factor
node.values - as.numeric(as.character(node.values))
# to get edges and memorize their order
edge - data.frame(tree$edge)
edge$order - as.numeric(rownames(edge))
# macth between node number and associated value
nTips - length(tree$tip.label)
nNodes - tree$Nnode
nTot - nTips+nNodes
if(upstream) values - data.frame(nodeID = c(1:nTot),
node.value=c(rep(1,nTips),node.values))
else values - data.frame(nodeID = c((1+nTips):nTot),
node.value=node.values)
# macth between edge and node
if(upstream) edgeatt - merge(edge, values, by.x=X2, by.y=nodeID)
#arete amont
else edgeatt - merge(edge, values, by.x=X1, by.y=nodeID) #arete aval
edgeatt - edgeatt[order(edgeatt$order),]
return(edgeatt$node.value)
}
#==FIN
FONCTION==
# Examples :
#1# Branch width according to the bootstrap value (for the branch upstream
the node)
# dataset
data(carnivora)
matrice - carnivora[1:20,c(6:8)]
rownames(matrice) - carnivora[1:20,5]
matrice - as.matrix(matrice)
#fonction to calculate the distance
library(ade4)
wizz-function(xx){tmp-dist.prop(as.data.frame(xx), 5); nj(tmp)}
#application to the dataset
matrice.phylo-wizz(matrice)
#bootstrapping
matrice.boot-boot.phylo(matrice.phylo, matrice, wizz, B=5)
#conversion from continues values to categorical values
matrice.boot2 - as.factor(matrice.boot2)
levels(matrice.boot2) - c(1,3)
#match between edge and bootstrap class
edgewidths - edgeAttributes(matrice.boot2, matrice.phylo)
# graph
plot(matrice.phylo, cex=1, font=1, edge.width=edgewidths)
nodelabels(matrice.boot, cex=1, col=blue, frame=none)
#2# Color according to the bootstrap value (downstream value)
edgecol - edgeAttributes(matrice.boot2, matrice.phylo, upstream=F)
plot(matrice.phylo, cex=1, font=1, edge.color=edgecol)
nodelabels(matrice.boot, cex=1, col=2, frame=none)
--
Isabelle Boulangeat, PhD student
Evolution, Modélisation et Analyse de la Biodiversité
Bureau 203, +33 (0) 476 635 733
Laboratoire d'écologie Alpine (LECA)
Grenoble, France
lab' s website : http://www-leca.ujf-grenoble.fr/
my website : http://j.boulangeat.free.fr/
2011/5/12 Alastair Potts pott...@gmail.com
Hi All,
I'm just submitting this request again, in case someone has a solution,
but I caught them at a bad time.
Any help would be greatly appreciated.
Cheers,
Alastair
On 2011/05/08 04:10 PM, Alastair Potts wrote:
Good day all,
I have been trying to figure out how the nodes and edges are related.
Specifically, I would like to colour edges based on bootstrap support
values of nodes (i.e. say a node has a bootstrap value 80%, then I
would like to make the preceding edge red).
I've explored the edgelabels() and nodelabels() functions and it
appears that the tree$edge and tree$node attributes do not appear to
be directly related (at least after ladderizing).
Any pointers as to how one would go about using the node values to
influence preceding edge attributes would be extremely appreciated.
Thank you very much for your time,
Cheers,
Alastair
--
-
Alastair Potts
PhD candidate
Botany Department
University of Cape Town
alastair.po...@uct.ac.za or pott...@gmail.com
University Private Bag, Rondebosch 7700, South Africa
or
PO Box 115, Loxton 6985, South Africa
Cell: 082 491-7275
-
[[alternative HTML version deleted]]
___
R-sig-phylo mailing list
R-sig-phylo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo
[[alternative HTML version deleted]]
___
R-sig-phylo mailing list
R-sig-phylo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo