找到具有最高中心性的节点

时间:2016-07-03 10:54:31

标签: r networking social-networking gephi

我有一个包含许多不同组件的网络。我需要找到Gephi和R中每个组件具有最高的亲密度和亲密度中心性的节点吗?

我可以提取全局网络具有最高中心性的节点,但我需要每个组件。我该怎么做?

1 个答案:

答案 0 :(得分:1)

以下是使用igraph为网络的每个连接组件查找具有最高亲密度中心性的顶点的示例:

library(igraph)
set.seed(1)

# random graph with two connected components
adj <- matrix(rbinom(n=900, size=1, prob=0.5), nrow=30)
adj[1:15,16:30] <- 0
adj[16:30,1:15] <- 0

g <- graph.adjacency(adj)

# assign a "label" property to keep track of original vertex labels after
# decomposing the network
V(g)$label <- labels(V(g))

# iterate over connected components and find vertex with maximum closeness
# centrality
connected_components <- decompose(g)

for (i in seq_along(connected_components)) {
    subnet <- connected_components[[i]]
    # Vertex with the largest centrality
    max_centrality <- V(subnet)[which.max(closeness(subnet))]$label
    print(sprintf("Vertex with max centrality for component %d: %s", i, max_centrality))
}

igraph还具有计算其他类型中心的功能,例如betweeness centrality