Wong
Wong

Reputation: 63

R igraph cluster nodes with the same colour (feature)

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

nodes <- 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)

This is what I get: enter image description here

What I want is to cluster the same colored nodes together, something similar as shown in the figure below. How can I do it?

enter image description here

Upvotes: 3

Views: 775

Answers (1)

ThomasIsCoding
ThomasIsCoding

Reputation: 101024

Maybe the option mark.groups in plot could help

plot(net,mark.groups = split(V(net)$name,V(net)$color))

which gives

enter image description here

Upvotes: 4

Related Questions