[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [igraph] About plotting communities calculated with outside function
From: |
Charles Novaes de Santana |
Subject: |
Re: [igraph] About plotting communities calculated with outside functions |
Date: |
Tue, 20 Mar 2012 12:04:02 +0100 |
WOW! I love igraph more and more every day hehehe It is simply amazing!!!!
Thanks, Tamas, for your "2-minutes advanced R course", thank you very much!!!
all the best!
Charles
On Mon, Mar 19, 2012 at 7:58 PM, Tamás Nepusz <address@hidden> wrote:
>> I am using a self-made function to identify communities in a network.
>> With this function I obtain in which community each of my vertices are
>> in (just like a $membership does). I would like to plot my network
>> representing this communities, just like we can do with the function
>> plot when we use variable of class "communities".
>
> Try this:
>
>> net <- graph.famous("Zachary")
>> members <- rep(1:2,17)
>> comms <- list(membership=members, vcount=vcount(net),
>> algorithm="my.fancy.algorithm")
>> class(comms) <- "communities"
>> plot(comms, net)
>
> The explanation is as follows. R variables may have an associated "class",
> and the method dispatch mechanism in R is influenced by the class of the
> first argument to a generic function. When you call plot(), R will examine
> the class of the first argument and it may call a "specialized" version of
> plot() if the first argument is of a given class. In particular, if the first
> argument has class "communities", plot() will forward the call to
> plot.communities() and then you get the fancy display that you have already
> seen.
>
> Now, the only thing we need is to construct an R object that "looks like" a
> member of the "communities" class. To figure out how such a class looks like,
> let us take a look at the output of a community detection method, say,
> walktrap:
>
>> wc <- walktrap.community(net)
>> wc2 <- unclass(wc)
>> wc2
>
> unclass() simply removes the class attribute from the wc object (so it
> becomes a "generic" R variable), so you can see that you practically need an
> R list with as many of the following members as possible:
>
> $membership - the membership vector
> $vcount - the number of vertices in the graph
> $algorithm - the name of the algorithm that produced the clustering
> $modularity - the modularity of the clustering, or the modularity after each
> split if this is a hierarchical clustering
> $merges - the order in which nodes are merged in a hierarchical clustering
>
> So, we can simply construct a list with the appropriate members manually
> (that's what I do in the first code snippet with the list() function), assign
> it to the "communities" class, and then the R method dispatch mechanism will
> do its magic.
>
> Best,
> Tamas
>
>
> _______________________________________________
> igraph-help mailing list
> address@hidden
> https://lists.nongnu.org/mailman/listinfo/igraph-help
--
Um axé! :)
--
Charles Novaes de Santana
http://www.imedea.uib-csic.es/~charles
PhD student - Global Change
Laboratorio Internacional de Cambio Global
Department of Global Change Research
Instituto Mediterráneo de Estudios Avanzados(CSIC/UIB)
Calle Miquel Marques 21, 07190
Esporles - Islas Baleares - España
Office phone - +34 971 610 896
Cell phone - +34 660 207 940