[Top][All Lists]

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

[igraph] Need help to rewrite some R code to python with igraph

From: Teddy Yang
Subject: [igraph] Need help to rewrite some R code to python with igraph
Date: Sat, 6 Apr 2013 23:13:31 +0800

I'm writing a simple python app of sth. like clustering of social network and found an article of similar work using R and igraph.

As a noob of R language, I find it is hard for me to rewrite R code below into python.

I have read some of the documentation of both implementations,but is confused by difference of them. 
I can't find equivalent of 'community.to.membership' in the documentation of igraph of python(actually, igraph.community_to_membership() exists); 'layout' of 'plot' in python but not in R so the figures are always different in shape...

Any help will be greatly appreciated. Thanks in advance!

# retrieved from: http://jean-robert.github.com/2012/01/22/cluster-your-facebook-friends.html
g <- graph.data.frame(ga.data, directed=FALSE)

gnc <- edge.betweenness.community(g, directed=FALSE)
m <- vector()
for (s in 0:nrow(gnc$merges) ) {
          memb <- community.to.membership(g,gnc$merge,steps=s)$membership
          m <- c(m,modularity (g, memb, weights=NULL))
ideal <- steps <- which(m==max(m)) - 1
gn.groups <- community.to.membership(g,gnc$merge, steps=ideal <- steps)$membership
V(g)$color <- gn.groups
V(g)$label <- V(g)$name # this is to show the friends' name on the plot                                                                              
#V(g)$label <- NA
V(g)$size <- 3

reply via email to

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