0

I am trying to draw a web of network but trying to put nodes in the same group close together.

'data' is the link data of two firms and I created a graph data named 'net', and 'group' is the attribute of nodes that I want to put nodes close based on.

y = data.frame(data$firm_id_1, data$firm_id_2)
net = graph.data.frame(y, directed = F)
V(net)$group = group

colors = rainbow(length(unique(group)))
set.seed(222)
l = layout_on_sphere(net)
plot(net,
     vertex.color = colors[group],
     vertex.size = 3,
     edge.arrow.size = 0.1,
     edge.color = 'grey',
     vertex.label.cex = 0.1,
     layout = l)

And this is the result that I got. I can see that all different colored nodes spread out.

Result

But I want to make the nodes in the same color (group) close together. And it would be good if I can keep this sphere shape of the web. Can anyone help me with this?

delight
  • 35
  • 2
  • If nodes in the same group are not close together, perhaps the group assignment is not very well grounded in the network structure? Have a look at the `minx`/`maxx` parameters of `layout_with_kk` and `layout_with_fr`. This won't keep the round shape, and if the bounds are too extreme, it may induce stresses in the spring system that inhibits proper relaxation, and produces a bad layout. Or use a circular layout and order your vertices around the circle according to the groups. – Szabolcs Jun 30 '23 at 14:06
  • You could separately create the layouts for each group, shift them by constant x and y values so that the coordinates of the different groups don't overlap, and merge the layouts into one matrix. Then use that layout matrix to plot the whole network. Won't look like one big ball, but rather there'd be a ball for each group. – Till Jun 30 '23 at 17:20
  • Here is an [answer](https://stackoverflow.com/a/45489448/4821142) that does something similar to what I describe in my comment. – Till Jun 30 '23 at 17:32
  • This [answer](https://stackoverflow.com/a/52672660/4752675) also gives a method to do what you are asking – G5W Jul 09 '23 at 12:43

0 Answers0