[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[igraph] Connected Components
From: |
Michael Knudsen |
Subject: |
[igraph] Connected Components |
Date: |
Thu, 5 Nov 2009 14:44:46 +0100 |
Hello,
I have a graph, and I want to plot only the biggest connected
component, but something appears not to be working as it is supposed
to do. First I read in my data:
> g <- graph(scan("protein_data.txt"),directed=F)
Read 8960 items
> g <- simplify(g)
I then use the clusters function to get the clusters:
> g_clusters <- clusters(g)
> which(g_clusters$csize == max(g_clusters$csize))
[1] 3
Hence cluster number three is the biggest. Since counting starts at 0
in igraph, this means that the connected component consists of the
vertices:
selected_vertices <- V(g)[which(g_clusters$membership == 2)]
But when I construct the corresponding subgraph, it isn't connected:
> h <- subgraph(g,selected_vertices)
> is.connected(h)
[1] FALSE
It really puzzles me; I can't see what is wrong with the approach
above. I'm absolutely sure that the index shifting is correct -- but
it shouldn't matter anyway: All components are, by definition,
connected, so even if I picked a wrong component it should still be
connected.
Any thoughts?
Thanks!
Michael Knudsen
--
Michael Knudsen
address@hidden
http://sites.google.com/site/micknudsen/
- [igraph] Connected Components,
Michael Knudsen <=