R:“连接"图表 [英] R: "connecting" graphs
问题描述
使用R,我创建并绘制了一个图形:
Using R, I created and plotted a graph:
library(igraph)
library(igraphdata)
data(karate)
#cluster
cfg <- cluster_fast_greedy(karate)
#plot entire graph
plot(cfg, karate)
#plot first subgraph
a = induced_subgraph(karate, cfg[[1]])
plot(a)
#plot second subgraph
b = induced_subgraph(karate, cfg[[2]])
plot(b)
#plot third subgraph
c = induced_subgraph(karate, cfg[[3]])
plot(c)
是否可以编写一些代码来显示哪个图形连接到哪个图形?
示例:绿色图形连接到橙色和紫色.紫色图仅连接到绿色图.并且橙色图形连接到绿色图形
Example: the green graph is connected to the orange and purple. the purple graph is only connected to the green graph. and the orange graph is connected to the green graph
("a"是橙色图,"b"是绿色图,"c"是紫色图)
("a" is the orange graph, "b" is the green graph, "c" is the purple graph)
b:c和a
c:b
a:b
推荐答案
对于二进制情况,问题是社区之间是否存在连接,可以执行以下操作.首先,根据社区的成员身份(属于"a","b"或"c")与社区签约.
For the binary case, where the question is whether a connection between communities exists or not, you could do the following. First, contract the communities based on their membership (belonging to "a", "b", or "c").
V(karate)$mem <- membership(cfg)
g <- contract.vertices(karate, V(karate)$mem, vertex.attr.comb = "ignore")
其次,删除循环和多条边:
Secondly, remove loops and multiple edges:
g <- simplify(g)
最后,提取相邻的节点(上面收缩它们之后现在等于社区):
Finally, extract adjacent nodes (which now equal communities after contracting them above):
sapply(1:vcount(g), function(x) adjacent_vertices(g, x))
这篇关于R:“连接"图表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!