igraph 中 10 个最具代表性的节点的子图
sub graph of the 10 most represented node in igraph
我有一个如下所示的属性数据框文件,还有一个如下所示的网络矩阵,我将属性正确地附加到数据上。但现在
1- 我想要最多的 30 个作者,在学位方面最具代表性,我知道我应该使用子图,但我不确定我的代码是否正确
2-我想要引用次数最多的作者,因为我想绘制它们。
有人可以帮助我吗?
my attribute set
Code Sector AUTHOR H.Index NumDocs References Citations
<fct> <fct> <fct> <int> <int> <int> <int>
S0004 SECS-S/01 AGATI P 2 6 134 32
S0005 SECS-S/01 AGOSTINELLI C 5 11 127 39
S0008 SECS-S/01 ALFO M 8 24 688 151
S0025 SECS-S/01 AREZZO MF 1 NA NA 11
my data
S0001 S0004 S0005 S0008 S0025 A0005 A0008 A0009
S0001 0 0 0 0 0 0 1 1
S0004 0 1 1 1 0 0 0 0
S0005 0 1 1 1 0 0 0 0
S0008 0 1 1 1 0 0 0 0
S0025 1 1 1 0 0 0 0 1
A0005 0 1 1 1 0 0 0 0
A0008 0 1 1 1 0 0 0 0
A0009 1 1 1 0 0 0 0 1
library("igraphdata")
library("igraph")
library("network")
library("statnet")
library("intergraph")
#Imagin my igraph object called PRIN_graph
#for the most represented authors:
DEG <-order(igraph::degree(PRIN_graph, mode = "all", normalized = T),decreasing = TRUE)
DEG[1:30]
HighDeg = induced_subgraph(PRIN_graph, DEG[1:30])
HighDeg
#how to get the vertex name for the most citations?
ci<- sort(unique(V(PRIN_graph)$Citations))
c<-sort(table(V(PRIN_graph)$Citations))
c
鉴于您的示例不可重现,假设您有一个 igraph
对象 g
,具有顶点属性 citations
(请参见下面的数据)。此外,前 10 个节点是 selected 而不是 30 个。您可以轻松更改它。
您可以简单地将逻辑向量传递给 induced_subgraph
命令,该命令用于对节点进行子集化。您可以通过组合 rank
和 <
来获得这样的向量,这也可以帮助您处理排名中可能存在的关系。有点不清楚你对领带的偏好是什么,我假设如果两个或更多观察值匹配排名 10,那么你将保留它们。另一种方法是保留第一个或最后一个,或者随机保留 select 个(查看 ties.method
中的 rank
)。
g.s <- induced_subgraph(g, rank(-V(g)$citations) < 11 )
get.vertex.attribute(g.s, "citations")
[1] 16 11 12 16 11 9 9 13 13 14 12
get.vertex.attribute(g.s, "label")
[1] "id1" "id4" "id6" "id7" "id10" "id12" "id13" "id15" "id17" "id19" "id20"
如您所见,返回了包含前 10 名被引用人物的图表。请注意,在等级 10 处有两个值为 9 的观测值,因此我们总共有 11 个节点。
您可以使用 degree 做完全相同的事情。首先将度数添加到属性列表中,然后对其进行子集:
V(g)$degree <- degree(g)
g.s <- induced_subgraph(g, rank(-V(g)$degree) < 11 )
数据:
library(igraph)
set.seed(123)
n <- 20
p <- 0.5
g <- random.graph.game(n, p)
# att attributes
V(g)$label <- paste0("id",1:n)
V(g)$citations <- rpois(n, 10)
vertex.attributes(g)
$label
[1] "id1" "id2" "id3" "id4" "id5" "id6" "id7" "id8" "id9" "id10" "id11"
[12] "id12" "id13" "id14" "id15" "id16" "id17" "id18" "id19" "id20"
$citations
[1] 16 5 6 11 5 12 16 5 2 11 6 9 9 4 13 8 13 6 14 12
我有一个如下所示的属性数据框文件,还有一个如下所示的网络矩阵,我将属性正确地附加到数据上。但现在 1- 我想要最多的 30 个作者,在学位方面最具代表性,我知道我应该使用子图,但我不确定我的代码是否正确
2-我想要引用次数最多的作者,因为我想绘制它们。
有人可以帮助我吗?
my attribute set
Code Sector AUTHOR H.Index NumDocs References Citations
<fct> <fct> <fct> <int> <int> <int> <int>
S0004 SECS-S/01 AGATI P 2 6 134 32
S0005 SECS-S/01 AGOSTINELLI C 5 11 127 39
S0008 SECS-S/01 ALFO M 8 24 688 151
S0025 SECS-S/01 AREZZO MF 1 NA NA 11
my data
S0001 S0004 S0005 S0008 S0025 A0005 A0008 A0009
S0001 0 0 0 0 0 0 1 1
S0004 0 1 1 1 0 0 0 0
S0005 0 1 1 1 0 0 0 0
S0008 0 1 1 1 0 0 0 0
S0025 1 1 1 0 0 0 0 1
A0005 0 1 1 1 0 0 0 0
A0008 0 1 1 1 0 0 0 0
A0009 1 1 1 0 0 0 0 1
library("igraphdata")
library("igraph")
library("network")
library("statnet")
library("intergraph")
#Imagin my igraph object called PRIN_graph
#for the most represented authors:
DEG <-order(igraph::degree(PRIN_graph, mode = "all", normalized = T),decreasing = TRUE)
DEG[1:30]
HighDeg = induced_subgraph(PRIN_graph, DEG[1:30])
HighDeg
#how to get the vertex name for the most citations?
ci<- sort(unique(V(PRIN_graph)$Citations))
c<-sort(table(V(PRIN_graph)$Citations))
c
鉴于您的示例不可重现,假设您有一个 igraph
对象 g
,具有顶点属性 citations
(请参见下面的数据)。此外,前 10 个节点是 selected 而不是 30 个。您可以轻松更改它。
您可以简单地将逻辑向量传递给 induced_subgraph
命令,该命令用于对节点进行子集化。您可以通过组合 rank
和 <
来获得这样的向量,这也可以帮助您处理排名中可能存在的关系。有点不清楚你对领带的偏好是什么,我假设如果两个或更多观察值匹配排名 10,那么你将保留它们。另一种方法是保留第一个或最后一个,或者随机保留 select 个(查看 ties.method
中的 rank
)。
g.s <- induced_subgraph(g, rank(-V(g)$citations) < 11 )
get.vertex.attribute(g.s, "citations")
[1] 16 11 12 16 11 9 9 13 13 14 12
get.vertex.attribute(g.s, "label")
[1] "id1" "id4" "id6" "id7" "id10" "id12" "id13" "id15" "id17" "id19" "id20"
如您所见,返回了包含前 10 名被引用人物的图表。请注意,在等级 10 处有两个值为 9 的观测值,因此我们总共有 11 个节点。
您可以使用 degree 做完全相同的事情。首先将度数添加到属性列表中,然后对其进行子集:
V(g)$degree <- degree(g)
g.s <- induced_subgraph(g, rank(-V(g)$degree) < 11 )
数据:
library(igraph)
set.seed(123)
n <- 20
p <- 0.5
g <- random.graph.game(n, p)
# att attributes
V(g)$label <- paste0("id",1:n)
V(g)$citations <- rpois(n, 10)
vertex.attributes(g)
$label
[1] "id1" "id2" "id3" "id4" "id5" "id6" "id7" "id8" "id9" "id10" "id11"
[12] "id12" "id13" "id14" "id15" "id16" "id17" "id18" "id19" "id20"
$citations
[1] 16 5 6 11 5 12 16 5 2 11 6 9 9 4 13 8 13 6 14 12