I currently have a network that is similar in node count and edge count to the following:

 set.seed(12)
 net <- sample_gnp(20, 1/4)
 V(net)$a <- sample(c(0, 1), vcount(net), replace = TRUE, prob = c(0.3, 0.7))
 V(net)$b <- sample(c(0, 1), vcount(net), replace = TRUE, prob = c(0.5, 0.5))
 V(net)$color <- V(net)$a + 4
 plot(net)

This creates a distinct network with a unique shape. Is there a way that I can only move the 20 nodes in this network randomly and maintain the shape? I want the network to look the same visually but with different nodes (node A at coordinate (a, b) is replaced by node G and they have the same number of edges). So ideally I want the graph to make a change like the following: (Same proportion of yellow to blue nodes but you can tell that they've moved around while simultaneously maintaining the shape)

Change after Rearrangement

2 Answers

0
Ben Nutzer On

The idea is to add the layout as additional node attributes, which are kept constant.

  l <- layout_nicely(net)
  V(net)$x <- l[,1]
  V(net)$y <- l[,2]

The other attributes are reshuffled following the same pattern in order to keep the attribute bundle intact.

  pattern <- sample(1:vcount(net))
  net2 <- net
  V(net2)$a <- V(net2)$a[pattern]
  V(net2)$b <- V(net2)$b[pattern]
  V(net2)$color <- V(net2)$color[pattern]

Now if you plot the result, you will hopefully end up with the desired output.

  par(mfrow = c(1,2))
  plot(net)
  plot(net2)
0
G5W On

I am not sure what you are looking for, but here are a couple of other options.

Rotate the graph

LO = layout_nicely(net)

LO2 = LO
alpha=pi/4
LO2[,1] =  cos(alpha)*LO[,1] + sin(alpha)*LO[,2]
LO2[,2] = -sin(alpha)*LO[,1] + cos(alpha)*LO[,2]

par(mfrow=c(1,2))
plot(net, layout=LO)
plot(net, layout=LO2)

Rotated graph

Flip side to side

LO3 = LO
alpha=pi/4
LO3[,1] = -LO3[,1]
plot(net, layout=LO)
plot(net, layout=LO3)

Flipped Graph