igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [igraph] Named vertexes from imported adjacency matrix


From: Gabor Csardi
Subject: Re: [igraph] Named vertexes from imported adjacency matrix
Date: Wed, 21 May 2008 23:01:21 +0200
User-agent: Mutt/1.5.17+20080114 (2008-01-14)

Szabolcs,

in the next igraph version the row names will be added automatically
as vertex attributes, this has been already added to the 
development version.

In the meanwhile, you can use the fact that graph.adjacency keeps 
the order of the vertices:

a <- matrix(sample(0:1, 16, rep=TRUE), 4)
rownames(a) <- colnames(a) <- letters[1:4]
g <- graph.adjacency(a)
V(g)$name <- rownames(a)
g

gives: 

Vertices: 4 
Edges: 9 
Directed: TRUE 
Edges:
          
[0] a -> c
[1] b -> b
[2] b -> c
[3] c -> a
[4] c -> b
[5] c -> c
[6] c -> d
[7] d -> b
[8] d -> d

G.

ps. please consider joining the list, otherwise you might miss some
answers, and your messages must be acknowledged "by hand" and that
can cause delay, even a couple of days. Thanks.

On Thu, May 22, 2008 at 01:45:32AM +1000, Szabolcs Feczak wrote:
> Hi,
> 
> I have just started to use this tool with R, so far I have achieved
> to read my adjacency matrix from CVS and plot the graph (with the method
> below),
> however I would like to have the vertex labels as the identifiers
> on the rows/columns not the automatically assigned numbers
> how can I do this automatically (I have more actors, the below is just a
> truncated file)
> 
> 
> 
> Thanks
> 
> S.
> 
> ps: great tool
> -------------------
> 
> 
> > read.csv(file="out8.csv",head=TRUE,row.names=1,check.names = FALSE)
>        123827 375857 530241 547613 661825 771302
> 123827      0      1      0      0      0      1
> 375857      1      0      0      0      0      1
> 530241      0      0      0      0      1      0
> 547613      0      0      0      0      0      1
> 661825      0      0      1      0      0      0
> 771302      1      1      0      1      0      0
> > graph.adjacency(read.csv(file="out8.csv",head=TRUE,row.names=1,check.names =
> FALSE))
> Vertices: 6
> Edges: 10
> Directed: TRUE
> Edges:
>          
> [0] 0 -> 1
> [1] 0 -> 5
> [2] 1 -> 0
> [3] 1 -> 5
> [4] 2 -> 4
> [5] 3 -> 5
> [6] 4 -> 2
> [7] 5 -> 0
> [8] 5 -> 1
> [9] 5 -> 3
> > g8 <- graph.adjacency(read.csv(file="out8.csv",head=TRUE,row.names=
> 1,check.names = FALSE))
> > tkplot(g8, layout=layout.fruchterman.reingold, vertex.size=12, 
> > vertex.label=V
> (g8)$name)

> _______________________________________________
> igraph-help mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/igraph-help


-- 
Csardi Gabor <address@hidden>    UNIL DGM




reply via email to

[Prev in Thread] Current Thread [Next in Thread]