1

我有一个包裹在圆环上的格子(图末尾的每个节点都链接到它们在网格上的对面)。

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,左手图的示例类似于我正在寻找的东西(这也是一篇非常好的论文!!)

http://ndg.asc.upenn.edu/files/Centola-2010-Science.pdf

4

1 回答 1

5

使用这个特殊的例子,Fruchterman-Reingold 3 维布局在一些实验中产生了最好的图形。

coordsFR <- layout.fruchterman.reingold(g, dim=3)
rglplot(g,vertex.size = 4,vertex.label = NA,vertex.color = "red",
        layout = coordsFR)

在此处输入图像描述

我也试过layout.sphere, layout.circle(不产生第三维)和layout.drl3 维。layout.drl3 维看起来比球体更好,但我上面展示的基于力的布局更好。

于 2014-04-25T12:49:10.397 回答