我有一个包裹在圆环上的格子(图末尾的每个节点都链接到它们在网格上的对面)。
require("igraph")
require("rgl")
n = 10
g = graph.lattice(c(n,n)) # create a square lattice (nxn)
plot(g,vertex.size = 0.5,vertex.size = 4,vertex.label = NA,vertex.color = "red")
# want to connect up the corners (horribly done)
v1 = seq(from =1, to = n,by = 1)
v2 = seq(from = n, to = n^2, by = n)
v3 = seq(from = n^2, to = n^2 - n+1, by = -1)
v4 = seq(from = v3[length(v3)],to = 1,by = -n)
a = cbind(rbind(v1,v2), rbind(v3,v4))
a2 = matrix(a,nrow=length(a),ncol = 1)
g = add.edges(g,a2)
plot(g,vertex.size = 4,vertex.label = NA,vertex.color = "red")
sum(degree(g2) != 4) # so all nodes do indeed have degree four, delighted!
我在创建/查找时遇到的问题是将图形绘制在圆环上的布局,理想情况下,我还想要 rglplot 的 3d 布局。
l2d = layout.a.lovely.torus(g,dim = 2)
l3d = layout.a.lovely.torus(g,dim = 3)
plot(g,vertex.size = 4,vertex.label = NA,vertex.color = "red",layout = l2d)
rglplot(g,vertex.size = 4,vertex.label = NA,vertex.color = "red",layout = l3d)
参见图 1,左手图的示例类似于我正在寻找的东西(这也是一篇非常好的论文!!)