1

I have a lattice that is wrapped on a torus (each nodes on the end of the graph are linked to their opposite on the grid).

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!

What im having a problem creating/finding is a layout that'll plot the graph on a torus, ideally i'd also like a 3d layout for rglplot.

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)

see figure 1, left hand graph for an example of something similar to what im looking for (also its a really nice paper!!)

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

John Paul
  • 12,196
  • 6
  • 55
  • 75
David
  • 326
  • 1
  • 11
  • What is wrong with either `layout.circle(g)` or `layout.sphere(g)`? For the paper you link to if you take any planar like graph, convert it to polar coordinates and then shift them away from the centroid it should return something that looks like the figure you cite. I'm not sure offhand how to wrap on a 3d torus though. – Andy W Apr 25 '14 at 12:35
  • Thanks, ya layout.circle(g) is grand, just not quite what im looking for! I've been playing with moving the centre of vertices around the centre of the circumference, just not very nice looking. – David Apr 25 '14 at 13:07

1 Answers1

5

Playing around with this particular example the Fruchterman-Reingold layout in 3 dimensions produced the nicest graph in a bit of experimentation.

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

enter image description here

I also tried layout.sphere, layout.circle (which doesn't produce a third dimension) and layout.drl with 3 dimensions. layout.drl with 3 dimensions looks better than the sphere, but the force based layout I show above is nicer.

Andy W
  • 5,031
  • 3
  • 25
  • 51