# [R] i graph library: how can generates a fully connected graph from a similarity matrix

Gábor Csárdi csardi.gabor at gmail.com
Fri Dec 12 09:46:18 CET 2008

```On Fri, Dec 12, 2008 at 2:10 AM, dinesh kumar <barupal at gmail.com> wrote:
> Dear R users
>
> I have a similarity matrix 100X100. I used this matrix as adjacency matrix
> to generate igraph graph object. Its a fully connected graph. The similarity
> score is the weight of the edge. Now I want to remove all possible lowest
> scores (edges) but I want to get back a fully connected graph (dont want any
> isolated vertex).How can I do it?

Actually your matrix is only 87x87.

If you mean that you want a graph with 87 vertices, and some edge
weights being zero, then you can simply do (assuming there are no
negative edge weights)

E(G)\$weight <- E(G)\$weight - 1

If you mean that you want to remove isolate vertices after creating
the graph, that would be:

G <- remove.vertices(G, V(G)[ degree(G)==0 ])

(For your data nothing really happens, there are no isolate vertices.)

> Also is there any possibility that I can remove the edges which dont pass a
> threshold (below 70% similarity score).

You can remove it initially, from the matrix:

or after, from the graph itself:

E(G)\$weight <- E(G)\$weight - 1
G2 <- delete.edges(G, E(G)[ weight < 0.7 ])

Gabor

ps. there is also an igraph mailing list, you can find it from the
igraph homepage. Just in case I miss your messages here.

> I attached the similarity matrix.
>
> I would appreciate the reply
>
>
> Dinesh
>
>
>
> --
> Dinesh Kumar Barupal
> Junior Specialist
> Metabolomics Fiehn Lab
> UCD Genome Center
> 451 East Health Science Drive
> GBSF Builidng
> University of California
> DAVIS
> 95616
> http://fiehnlab.ucdavis.edu/staff/kumar
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help