[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [igraph] Overlapping Networks by the Edges
From: |
Gábor Csárdi |
Subject: |
Re: [igraph] Overlapping Networks by the Edges |
Date: |
Tue, 12 Jan 2010 19:49:34 +0100 |
Lorenzo,
On Tue, Jan 12, 2010 at 4:04 PM, Lorenzo Isella
<address@hidden> wrote:
> Dear All,
> Maybe a simple thing, but I am experiencing problems.
> The snippet below, together with the text file text_graph.dat (graph
> adjacency list where the nodes are labeled by long integers) generates two
> connected networks g and g2.
> g2 is in a sense a subgraph of g1 since both its nodes and edges are. I
> would like to plot g and highlight with a different color the nodes and
> edges in common with g2.
> Does anyone know how to achieve that? In particular, selecting the common
> edges between the two graphs is driving me mad.
> Any help is appreciated.
> Cheers
>
> Lorenzo
>
>
> library(igraph)
>
> fn <- paste("test_graph.dat")
>
> network <- read.table(fn,header=FALSE)
>
> g <- graph.data.frame(network,dir=FALSE)
>
> g <- simplify(g)
>
> #select largest cluster
>
> node_sel <- which(clusters(g)$membership==0)
>
> g <- subgraph(g,V(g)[node_sel-1])
>
>
> V(g)$id <- seq(vcount(g))-1
>
> remove_nodes <- seq(0,vcount(g)-1, by=4)
>
> g2 <- delete.vertices(g,V(g)[remove_nodes])
>
> node_sel <- which(clusters(g2)$membership==0)
>
> g2 <- subgraph(g2,V(g2)[node_sel-1])
>
>
>
> l <- layout.fruchterman.reingold(g)
> l <- layout.norm(l, -1,1, -1,1)
>
>
> pdf("test_graph.pdf")
>
> plot(g, layout=l,
> vertex.label.dist=0.5
> , vertex.color="#ff000033"
> ,
> vertex.frame.color="#ff000033",
> edge.color="#55555533"
> ,vertex.label=NA,
> vertex.size=4)
>
>
> dev.off()
So far it is good. To add the second graph on top, just do this:
l2 <- l[ V(g)$name %in% V(g2)$name, ]
plot(g2, layout=l2, vertex.color="red", vertex.frame.color="red",
edge.color="black", vertex.label=NA, vertex.size=4, add=TRUE,
rescale=FALSE)
Tell me if something is not clear. Best,
Gabor
[...]
--
Gabor Csardi <address@hidden> UNIL DGM