[英]Degrees in I graph
I am a Newbie in I-graph.我是 I-graph 的新手。 I wish to know.我想知道。
If there is any more tutorial/book with a more involved treatment of degree function, please let me know如果还有更多涉及学位 function 处理的教程/书籍,请告诉我
Warm Regards温暖的问候
SHRINIVAS神殿
I think you can use the vertex function V()
, degree()
, and base R functions like which()
to get what you want.我认为您可以使用顶点 function V()
、 degree()
和基础 R 函数,如which()
来获得您想要的。 See below.见下文。
library(igraph)
set.seed(12345)
# Generate a graph with a heterogeneous degree distribution
g <- sample_fitness_pl(
no.of.nodes = 200,
no.of.edges = 1000,
exponent.out = 2
)
# Plot to confirm
plot(g, vertex.label = "", vertex.size = 2)
# Collect the degree sequence
k_i <- degree(g)
# And the distinct observed degrees
k_bins <- sort(unique(k_i))
# Plot the degree histogram
hist(k_i, breaks = 20)
# Let's look at nodes with k_i = 10
n <- 10
# We can use the base R function `which()` to return the node
# IDs of those nodes with k_i = n
V(g)[which(k_i == n)]
## [1] 126 134 145 154
I think for (3) you want an induced subgraph with only those nodes with k_i > n.我认为对于 (3),您需要一个仅包含 k_i > n 的节点的导出子图。 However, in the induced subgraph, those nodes will not necessarily have the same degree as in the original graph.然而,在导出子图中,这些节点不一定具有与原始图中相同的度数。 If that isn't quite what you're looking for, see the manual here to see if there's a better option.如果这不是您想要的,请参阅此处的手册以查看是否有更好的选择。
# These are the nodes with k_1 >= n
plot(g, vertex.label = "", vertex.size = 2, vertex.color = ifelse(k_i > n, 2, 1))
h <- induced_subgraph(
g,
vids = V(g)[which(k_i >= n)]
)
plot(h, vertex.label = "", vertex.size = 3, vertex.color = 2)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.