[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [igraph] assigning attributes to vertices
From: |
Gábor Csárdi |
Subject: |
Re: [igraph] assigning attributes to vertices |
Date: |
Mon, 17 Nov 2008 11:19:45 +0100 |
Hi Patrick,
On Sun, Nov 16, 2008 at 9:22 PM, patrick wintrode <address@hidden> wrote:
> Hi.
>
> To get a feel for igraph, I'm trying to reproduce the example in
> "screenshots" where an Erdos-Renyi graph is colored by cluster size. I'm
> using R instead of python (I'm also fairly new to R).
>
> After making the ER graph (named g), I did the following:
>
> cl <- clusters(g)$membership
> plot(g, layout=layout.fruchterman.reingold, vertex.size=6, vertex.label=NA,
> vertex.color=cl)
>
> Obviously, this colors by cluster # and not by size. When I try:
Yeah, but actually it is incorrect, the cluster ids start with zero,
and the R colors are indexed from one. So you need
vertex.color=cl+1
> cm <- clusters(g)$csize
> plot(g, layout=layout.fruchterman.reingold, vertex.size=6, vertex.label=NA,
> vertex.color=cm)
>
> The coloring is completely wrong.
Well, it is just the coloring you have specified....
> I'm wondering how to assign cluster size as an attribute to the vertices.
g <- erdos.renyi.game(300, 250, type="gnm")
clu <- clusters(g)
V(g)$csize <- clu$csize[ clu$membership+1 ]
V(g)$color <- as.integer(as.factor(V(g)$csize))
g$layout <- layout.fruchterman.reingold(g)
plot(g, vertex.size=4, vertex.label=NA)
Best,
Gabor
> Thanks.
>
> Patrick
>
>
>
> _______________________________________________
> igraph-help mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/igraph-help
>
--
Gabor Csardi <address@hidden> UNIL DGM