2

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

Wong
  • 63
  • 6
  • 1
    The answer to a previous question may help. [(igraph) Grouped layout based on attribute](https://stackoverflow.com/a/52672660/4752675) – G5W Aug 08 '20 at 12:47

1 Answers1

1

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)
Wong
  • 63
  • 6