在圆环上绘制igraph对象

时间:2014-04-25 11:59:59

标签: r layout igraph rgl mathematical-lattices

我有一个包裹在圆环上的点阵(图表末尾的每个节点都链接到网格上的相反位置)。

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

1 个答案:

答案 0 :(得分:4)

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

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

enter image description here

我还尝试了layout.spherelayout.circle(不生成第三维)和layout.drl三维。具有3个维度的layout.drl看起来比球体更好,但我在上面显示的基于力的布局更好。