Reputation: 331
I have a network with many different components. I would need to find the node with the highest betweeness and closeness centrality for each of these components in Gephi and in R?
I can extract the nodes with the highest centrality for the global network but I need it per component. How do I do this?
Upvotes: 0
Views: 2680
Reputation: 4960
Here is an example of finding the vertices with the highest closeness centrality for each connected component of a network using 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 also has functions to compute other types of centralities, e.g. betweeness centrality.
Upvotes: 1