如何在igraph中得到一个度中心性较大的顶点

时间:2022-12-28 21:47:33

i want to get the vertex with the highest degree centrality using igraph R, i tried with :

我想用igraph R得到最高度中心性的顶点,我试过:

V(g)[degree(g,V(g)$id) == which.max(degree(g))]

But it doesn't work.

但它不工作。

1 个解决方案

#1


0  

Try

试一试

library(igraph)
set.seed(5)
g <- ba.game(100)
V(g)$id <- paste0("id", 1:100)
(idx <- which(degree(g)==max(degree(g))) )
V(g)$id[idx]
# [1] "id1" "id2"

# optional plot
cols <- rep("blue", vcount(g)); cols[idx] <- "red"; plot(g, vertex.shape="none", vertex.label.color=cols, edge.arrow.size=.5)

#1


0  

Try

试一试

library(igraph)
set.seed(5)
g <- ba.game(100)
V(g)$id <- paste0("id", 1:100)
(idx <- which(degree(g)==max(degree(g))) )
V(g)$id[idx]
# [1] "id1" "id2"

# optional plot
cols <- rep("blue", vcount(g)); cols[idx] <- "red"; plot(g, vertex.shape="none", vertex.label.color=cols, edge.arrow.size=.5)