如何使用igraph

时间:2016-09-15 12:46:19

标签: r igraph network-analysis

我在网络上执行了社区检测算法,并将群集列表作为输出。我想用这些集群做几件事,但我正在努力操纵它们。首先,我想通过引用例如Cluster 1来创建子图。下面是我的一些代码。

我的数据框看起来像这样 Person1 Person2 Volpc
人A人B 0.08
人A A夫人0.08
人A女士B 0.23
人A C 0.38
B女士CC先生0.29
B夫人A女士0.23
B女士B人0.87
Lady C Lady A 0.87
Lady C Lady B 1.01
D先生,CC先生0.94

#First I created an adjacency matrix from by data set of links LinkSummary for which
#the weight is named Volpc

G <- graph.data.frame(LinkSummary,directed=FALSE);
A <- as_adjacency_matrix(G,type="both",names=TRUE,sparse=FALSE,attr="Volpc");


#build a graph

netw <- graph.adjacency(A,weighted=T, mode="undirected")

#remove loops
netw <- simplify(netw)

#I used the walktrap algorithm to find communities
wt<- walktrap.community(netw, steps=6,modularity=TRUE,weights = E(G)$Volpc)

我一直在试验群集的数量,以找到最佳解决方案  没有这个选项,很多节点都放在一个大型集群中。这有助于打破它们。

#increase number clusters
wt2 <- cut_at(wt, no=300)

我把结果放到一个表中并输出到excel并产生一些看起来像这样的东西

memtwt <- table(names, wt2 )
write.table(memtwt, file="clipboard-16384", sep="\t", row.names=TRUE) increase buffer

节点 1 2 3 4
人A 1 0 0 0
Lady A 0 1 0 0
B女士 1 0 0 0
Lady C 0 0 0 1
D先生 0 0 1 0
人B 0 0 1 0
CC先生 1 0 0 0

不幸的是,我的很多群集看起来都是基于与一个节点的联系。 要查看我创建子网的交互 (使用此处的代码Creating Subgraph using igraph in R

# we want a sub-network containing the following nodes:
subv <- c('Person A','Lady B','Mr CC')


# create a sub-network composed by ONLY the nodes in subv and the edges 
# between them
g2 <- induced.subgraph(graph=netw,vids=subv)

plot(g2,  vertex.size=3, edge.color="black",edge.width=E(g2)$weight/10)

我想要的是能够将每个群集分配给变量以便我可以 每次我有不同的结果时查看子网,而不输入名称列表,如...

subv <- wt2(1)
g3 <- induced.subgraph(graph=netw,vids=subv)

有人可以帮我吗?

0 个答案:

没有答案
相关问题