igraph in R: Arrange the same coloured nodes next to each other

Viewed 178

My example:

library(igraph)
links <- cbind.data.frame(from = rep("A", 6),
                  to = LETTERS[1:6],
                  weight = rep((1:3), each =2))

nodes <- cbind.data.frame(id = LETTERS[1:6],
                           feature = rep((1:3), each =2))

net <- graph_from_data_frame(d = links, vertices = nodes, directed = T) 
V(net)$color <- V(net)$feature
plot(net, vertex.size=30, edge.arrow.size = 0)

The resulting figure looks like below:

enter image description here

What I want is to arrange the same colored node together, as shown in the following figure. The same colored nodes are next to each other.

enter image description here

1 Answers

I have found a very simple way to do it. Just need to use as_star layout

LO <- layout_(net, as_star())
plot(net, vertex.size = 30, edge.arrow.size = 0, layout = LO)
Related