[R] Nodes & edges with similarity matrix

Gabor Csardi csardi at rmki.kfki.hu
Tue Aug 28 23:44:58 CEST 2007


Paul,

i have no idea what functionality you need from graph, but 
if the igraph package can do what you want then it can 
easily convert this to a graph for you, basically it is just

threshold <- 0.5
g <- graph.adjacency(sim>threshoold)

or you can create a weighted graph:

g <- graph.adjacency(sim, weighted=TRUE)

or a weighted graph after a threshold:

sim2 <- sim
sim2[ sim<threshold ] <- 0
g <- graph.adjacency(sim2, weighted=TRUE)

etc.

Best,
Gabor

On Tue, Aug 28, 2007 at 02:25:27PM -0700, H. Paul Benton wrote:
> Hello,
> 
>     I apologise if someone has already answered this but I searched and
> googled but didn't find anything.
> 
>     I have a matrix which gives me the similarity of each item to each
> other. I would like to turn this matrix into something like what they
> have in the graph package with the nodes and edges.
> http://cran.r-project.org/doc/packages/graph.pdf . However I cannot find
> a method to convert my matrix to an object that graph can use.
> 
> my similarity matrix looks like:
> > sim[1:4,]
>                 a          b          c          d
> [a]  1.000000000  0.0223676  0.9723831  0.3943310
> [b]  0.325141612  1.0000000  0.9644216  0.5460461
> [c]  0.002109751  0.3426540  1.0000000  0.7080224
> [d]  0.250153137  0.1987485  0.7391222  1.0000000
> 
> please don't get caught up with the numbers I simple made this to show.
> I have not produce the code yet to make my similitary matrix.
> 
> Does anyone know a method to do this or do I have to write something. :(
> If I do any starter code :D jj. If I've read something wrong or
> misunderstood my apologies.
> 
> cheers,
> 
> 
> Paul
> 
> 
> -- 
> Research Technician
> Mass Spectrometry
>    o The
>   /
> o Scripps
>   \
>    o Research
>   /
> o Institute
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
Csardi Gabor <csardi at rmki.kfki.hu>    MTA RMKI, ELTE TTK



More information about the R-help mailing list