Hello
Thanks to Emmanuel's feedback I have worked out an answer to my own query:
# Demostration of cophyloplot where congruent and incongruent links
# are displayed in two different colors
# Hosts(H) and parasites (P) share a common topology (com.tree)
# with 1 to 1 (congruent) H-P links.
# Other part of the tree is different between H and P with random
# (incongruent) H-P links.
#
library(ape)
# set numbers of congruent and incongruent links
Nc = 6
Ni = 4
com.tree - rtree(Nc) # topology shared by H and P trees
H.tree - rcoal(n=Ni, tip.label=paste(I,1:Ni)) # H different topology
P.tree - rcoal(n=Ni, tip.label=paste(I,1:Ni)) # P different topology
#
# bind shared and unshared topologies:
com.tree$root.edge - H.tree$root.edge - P.tree$root.edge - runif(1)
H.tree - com.tree + H.tree
P.tree - com.tree + P.tree
#
# HPgamma creates HP matrix with coevl links in common part of tree and
# random links RESTRICTED TO random part of the tree
HPgamma - function (NH, NP, Nrand) { # input is no. H, P and Ni
HP - diag(1, NH, NP) #diagonal 1 matrix of NH rows and NP cols
HP2 - diag(1, Nrand)
#The following randomizes the links of the non-coevolving part of the
tree:
i - sapply(seq_len(Nrand), function(x) sample(seq_len(Nrand)[-x], 1))
HP2 - matrix(0, Nrand, Nrand)
HP2[cbind(seq_len(Nrand), i)] - 1
HP3 - which(HP2 ==1, arr.in=TRUE) #get coordinates of incongruent links
HP[HP3] - 1
for (i in 1:Nrand) HP[i,i] -0
return(HP)
}
#
# Proper script starts here:
# 1. Sort assoc= input of cophyloplot. Incongruent links go first
HP - HPgamma(Nc+Ni,Nc+Ni,Ni)
rownames(HP)- rev(H.tree$tip.label)
colnames(HP)- rev(P.tree$tip.label)
HP.LUT - which(HP ==1, arr.in=TRUE)
links - cbind(rownames(HP)[HP.LUT[,1]],colnames(HP)[HP.LUT[,2]])
# 2. create a binary vector where 1 = incongruent and 0 = congruent
# order follow 'links' above
x - c(rep(1, Ni), rep(0, Nc))
# 3. color vector red = incongruent, blue = congruent
cols - c(blue,red)[(x==1)+1]
# 4. plot trees:
cophyloplot(H.tree, P.tree, assoc=links, use.edge.length=TRUE,
gap=0.5, space=8, col= cols)
# Voilà!
El 28/05/2014 11:20, Emmanuel Paradis escribió:
These options can be vectors with several values (and they are
recycled if needed), so you should be able to specify different values
for each link. If not, there is a problem.
E.
Wed, 28 May 2014 11:15:35 +0200 Juan Antonio Balbuena
j.a.balbu...@uv.es:
Hello Emmanuel,
I know that cophyloplot() has these options, but apparently
there is no direct way to use two or more types of lines to mark
links. I specifically wish to mark congruent links in both trees
using a different type of line than that for incongruent links.
This is not too difficult to implement manually but it would be
great to write a function doing this.
Best
Juan
El 28/05/2014 11:03, Emmanuel Paradis escribioacute;:
Hi Juan, cophyloplot() has the options
col, lwd, and lty which specify the aspects of the association
lines. Le 27/05/2014 16:09, Juan Antonio Balbuena a
eacute;crit :Hello This is a simple question and
hope that there is a simpleanswer. Plotting a
tanglegram, I would like to write a function where congruent
tips on both trees are marked, say, with continuous lines,
whereas incongruent tips are marked
differently (for instance withstippled lines). A
starting point could be using cophyloplot() specifying
assoc=NULL and then use segment() to plot the lines
accordingly, but how can one get the x, y
coordinates for segment()? This is not possible (at least
easily) because this function uses a different system than
plot.phylo(). HTH Best, Emmanuel
Any thoughts will be much appreciated.
Juan A. balbuena --
Dr. Juan A. Balbuena Cavanilles Institute of
Biodiversity and Evolutionary Biology University of
Valencia http://www.uv.es/~balbuena
http://www.uv.es/%7Ebalbuena P.O. Box 22085
http://www.uv.es/cophylpaco
http://www.uv.es/cavanilles/zoomarin/index.htm 46071
Valencia, Spain e-mail: j.a.balbu...@uv.es
mailto:j.a.balbu...@uv.estel. +34 963 543 658
fax +34 963 543 733
*NOTE!*For shipments by EXPRESS COURIER use the following
street address: C/ Catedraacute;tico
Joseacute; Beltraacute;n 2, 46980 Paterna (Valencia), Spain.
___ R-sig-phylo mailing
list - R-sig-phylo@r-project.org