0

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?

DroppingOff
  • 331
  • 3
  • 17
  • You could improve your question. For the R part, please read [how to provide minimal reproducible examples in R](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example#answer-5963610). Then edit & improve it accordingly. A good post usually provides minimal input data, the desired output data & code tries - all copy-paste-run'able. – lukeA Jul 03 '16 at 10:58
  • Hi, I know that it is better to add data but I cannot do it and it is protected data in this case. Thank you veyr much for your advice. In gephi there is no code. – DroppingOff Jul 03 '16 at 11:02
  • I have a file with a edge table, in case that is useful – DroppingOff Jul 03 '16 at 11:10
  • For R, have a look at the `igraph` package, with which you - among many other things - build reproducible example graphs. Such a graph will help illustrating your problem. – lukeA Jul 03 '16 at 11:23

1 Answers1

1

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.

Keith Hughitt
  • 4,860
  • 5
  • 49
  • 54
  • Hey Keith, how can I keep the original label of the node? In the moment I decompose, your answer returns: [1] "Vertex with max centrality for component 3256: 1" and instead or a 'rename ' to 1 of the node, I need the original label of the node which could be 325 for example – DroppingOff Jul 03 '16 at 17:53
  • 1
    Hi @DroppingOff, good question. I updated the code example so that it keeps track of the original node labels. Because you can attach arbitrary metadata to nodes and edges in igraph, you can simply store the original labels as above. – Keith Hughitt Jul 03 '16 at 23:44
  • Thank you so much! – DroppingOff Jul 04 '16 at 07:19