1

我想使用更大的图作为源从一组种子节点生成第一个交互器子图。源图很大,有超过 300,000 条边,我的种子节点约为 300。子图(或多个子图)应包含每个种子节点的第一个交互器。

我已经在这篇文章中使用 R 中的 igraph 创建子图应用了代码, 但它只给了我一个很大的子图。我期望一个大的子图(大陆)和另一个与这个更大的图(岛屿)没有联系的子图。

示例代码:

g <-erdos.renyi.game(50, 3/50)
seeds <- c(1,4,5,6,40,30)
sg <- decompose.graph(g)
neighverts <- unique(unlist(sapply(sg,FUN=function(s){if(any(V(s) %in% seeds)) V(s) else NULL})))
g1 <- induced.subgraph(graph=g,vids=neighverts)

该图为g1我提供了decompose.graph. 该图包含我的种子节点和其他不是种子节点的第一个交互器的节点。我正在寻找的是一个子图或子图列表,其中包含种子节点及其第一个交互器。也许我应该尝试使用neighborhood组功能?

提前谢谢了

编辑1:

按照 Gabor 的建议,我使用neigborhood了函数 with order=1。但是,我仍然没有得到我预期的结果。请在下面找到详细示例:

mat <- structure(list(X1 = c("5203820", "9985655", "5203820", "1795907","2190697", "5203820", "3233174", "1773848", "892104", "9976862","9987167", "9987134", "1211741", "1722252", "9986835", "9986879","9986835", "61145", "3442328", "5203820", "9987075", "3442328","1773848", "119371", "9986887", "2190697", "9987032", "9974927","9986835", "892104", "3744713", "9974927", "5118892", "9987134","9987134", "3442328", "2190697", "5203820", "9985655", "9987167","9990684", "3233174", "5203820", "9990684", "3744713", "9990684","9990684", "61145", "9990684", "3442328", "5378006", "9987035","9987035", "9987088", "3442328", "5118895"), X2 = c("61145","9987167","4928047", "9975931", "3744713", "3744713", "9975931","3820326", "9987100", "9987035", "9990670", "9990670", "9984628","3588994", "9986879", "9987059", "9987059", "9978463", "9986877","1795907", "9987142", "3588994", "1211741", "2111600", "9987124","1773848", "9987228", "9987100", "3442328", "3820326", "9983385","9978897", "9987019", "9987059", "5143742", "5143742", "9983385","9978463", "9987134", "9986887", "9990684", "9990684", "9990684","5373267", "9990684", "5389588", "5389374", "9990684", "5393513","9987088", "9987088", "9987035", "5118895", "9987088", "9987035","9987088")), .Names = c("X1", "X2"), row.names = c(NA, -56L), class = "data.frame")

g <- graph.data.frame(mat, directed=F)
seeds <- c('1722252', '9990670', '3442328', '5378006', '9990684', '9978463')
g1 <- induced.subgraph(g, vids = unlist(neighborhood(g, 1, nodes = seeds)))

plot(g1)

图像1.

结果显示节点“5143742”和“9987134”之间有一条边。我的预期结果只是种子节点(种子)以及它们与第一个交互器之间的边,不包括第一个交互器之间的那些边

再次感谢

4

1 回答 1

3

要获得仅包含种子顶点与其第一个交互器之间的边的诱导子图,您可以subgraph.edges按照注释中的指示使用。

g1 <- subgraph.edges(g, unlist(get.adjedgelist(g)[seeds]) )
于 2015-02-18T17:55:25.433 回答