有没有办法 link 一个图到另一个图(igraph)的任何特定顶点?
Is there any way to link a graph to any particular vertex of another graph (igraph)?
我想通过将一个图的节点连接到另一个来连接两个独立的图
比如我有两个图G和H
G = 1-3,1-5,5-9,5-21,21-22
H = 0-31,31-32,31-34,31-35,35-88
我想 link 通过将图 H 的节点 0 连接到图 G 的节点 5 link 图 H 和图 G
1-3,1-5,5-9,5-21,21-22,5-0, 0-31,31-32,31-34,31-35,35-88
请使用库 igraph
.
的 edge()
函数从您的数据中找到以下一种可能的解决方案
Reprex
- 第 1 步:构建和可视化图表
G
和 H
library(igraph)
# Building the graph 'G'
G <- graph(edges = c("1","3", "1","5", "5","9", "5","21", "21","22"), directed = FALSE)
#Building the graph 'H'
H <- graph(edges = c("0","31", "31","32", "31","34", "31","35", "35","88"), directed = FALSE)
# Visualizing the graph 'G'
plot(G)
# Visualizing the graph 'H'
plot(H)
- 第 2 步:将两个图
G
和 H
与边 0-5
组合
# Building the graph 'Results'
Results <- G + H + edge("0", "5")
# Visualizing the graph 'Results'
plot(Results)
由 reprex package (v2.0.1)
创建于 2022-01-01
你可以试试disjoint_union
+ add_edges
> add_edges(disjoint_union(G, H), c("0", "5"))
IGRAPH 6cbfa1f UN-- 12 11 --
+ attr: name (v/c)
+ edges from 6cbfa1f (vertex names):
[1] 1 --3 1 --5 5 --9 5 --21 21--22 0 --31 31--32 31--34 31--35 35--88
[11] 5 --0
我想通过将一个图的节点连接到另一个来连接两个独立的图
比如我有两个图G和H
G = 1-3,1-5,5-9,5-21,21-22 H = 0-31,31-32,31-34,31-35,35-88
我想 link 通过将图 H 的节点 0 连接到图 G 的节点 5 link 图 H 和图 G
1-3,1-5,5-9,5-21,21-22,5-0, 0-31,31-32,31-34,31-35,35-88
请使用库 igraph
.
edge()
函数从您的数据中找到以下一种可能的解决方案
Reprex
- 第 1 步:构建和可视化图表
G
和H
library(igraph)
# Building the graph 'G'
G <- graph(edges = c("1","3", "1","5", "5","9", "5","21", "21","22"), directed = FALSE)
#Building the graph 'H'
H <- graph(edges = c("0","31", "31","32", "31","34", "31","35", "35","88"), directed = FALSE)
# Visualizing the graph 'G'
plot(G)
# Visualizing the graph 'H'
plot(H)
- 第 2 步:将两个图
G
和H
与边0-5
组合
# Building the graph 'Results'
Results <- G + H + edge("0", "5")
# Visualizing the graph 'Results'
plot(Results)
由 reprex package (v2.0.1)
创建于 2022-01-01你可以试试disjoint_union
+ add_edges
> add_edges(disjoint_union(G, H), c("0", "5"))
IGRAPH 6cbfa1f UN-- 12 11 --
+ attr: name (v/c)
+ edges from 6cbfa1f (vertex names):
[1] 1 --3 1 --5 5 --9 5 --21 21--22 0 --31 31--32 31--34 31--35 35--88
[11] 5 --0