Skip to content

combine 2 plots - one network and one phylogenetic tree

6 messages · Alan Haynes, Charles Novaes de Santana, Augusto Ribas

#
Hi Augusto,

Which layout do you want to reproduce? The layout of the first network
you plot?

Do you know the "tkplot" function of igraph? You can plot the network
using tkplot and then you can read the coordinates of the nodes into a
variable. Like this:

tkplot(dados.igraph,layout=layout.fruchterman.reingold,vertex.color=c(rep("red",6),rep("green",6)),edge.arrow.size=0.2,vertex.size=20,vertex.label=c(paste("P",1:6,sep=""),paste("H",1:6,sep="")));
my_layout<-tkplot.getcoords(1);

So you can use the variable my_layout (a matrix of coordinates) in
other plots of network you want to:

plot(dados.igraph, layout=my_layout)

Sorry if it is not what you are looking for. Maybe if you write
directly to the igraph-help mailing list you can have more luck. They
use to answer the questions quickly:

https://groups.google.com/forum/?fromgroups#!forum/network-analysis-with-igraph

All the best,

Charles
On Wed, Jun 20, 2012 at 4:04 PM, Augusto Ribas <ribas.aca at gmail.com> wrote:

  
    
#
What i want is something like:

#Take the order of the hosts from the tree
order<-host.tree$tip.lab

par(mfrow=c(2,1))

#remove the host names from the tree to not repeat the network
plot(host.tree,use.edge.length=F,direction="downwards",show.tip.label =F)

#now plot the network, with the order of the tree
plotweb(dados[,order],method = "normal")

#but cant make the  H2 label of the tree in the exactly place of the
#H2 of the network, and for all the Host species.
#I dont know a strategy to make a plot this way.
#The distance from H1 to H2 to H3 are variable in the network plot, i
#would like someway to make them be equall, then maybe i could work the
#mar parameter in par to make things plug right, i dont know.

#something like this draw:
http://oi47.tinypic.com/2j2szcy.jpg

2012/6/20 Alan Haynes <aghaynes at gmail.com>:

  
    
#
What i wanted is something like:
#Data
dados<-matrix(c(1,1,1,1,0,0,
                0,1,1,1,0,0,
                0,0,1,1,0,0,
                0,0,0,0,1,0,
                0,0,0,0,0,1,
                0,0,0,0,0,1),byrow=T,ncol=6,nrow=6,
                dimnames=list(paste("P",1:6,sep=""),paste("H",1:6,sep="")))
dados


library(igraph)
dados.network<-cbind(expand.grid(rownames(dados),colnames(dados)),Presence=c(dados[,]))
dados.network<-dados.network[which(dados.network$Presence==1),1:2]
dados.igraph<-graph.data.frame(dados.network)

library(ape)
host.tree<-rtree(6,rooted=TRUE,tip.label=paste("H",1:6,sep=""))

ordem<-as.numeric(as.factor(host.tree$tip.label))

#Plot
par(mfrow=c(2,1),mar=c(0,9.5,0,9.5))
plot(host.tree,use.edge.length=F,direction="downwards",show.tip.label=F)
par(mar=c(0,0,0,0))
plot(dados.igraph,layout=matrix(c(1:6,ordem,rep(c(1,2),each=6)),ncol=2,nrow=12),
vertex.color=c(rep("red",6),rep("green",6)),edge.arrow.size=0.2,vertex.size=20,
vertex.label=c(paste("P",1:6,sep=""),paste("H",1:6,sep="")))

I asked on the igraph list like suggest and got a hint that made me
work better on the layout.
Thanks for the help guys.


2012/6/20 Augusto Ribas <ribas.aca at gmail.com>: