# Group nodes in igraph

**URL:** https://igraph.discourse.group/t/group-nodes-in-igraph/601
**Category:** Usage
**Tags:** R
**Created:** [24 January 2021 07:44 UTC](https://igraph.discourse.group/t/group-nodes-in-igraph/601 "2021-01-24T07:44:30Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![gadepallivs](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/gadepallivs/32/439_2.png) [@gadepallivs](https://igraph.discourse.group/u/gadepallivs)
#### Post date: [24 January 2021 07:44 UTC](https://igraph.discourse.group/t/group-nodes-in-igraph/601/1 "2021-01-24T07:44:30Z")

</div>

Is there a layout in igraph that can arrange the nodes in 2 separate groups ? To achieve something like this image ?

 ![image](https://global.discourse-cdn.com/free1/uploads/igraph/original/1X/b19c736416f0396dbb991beb5a79ec3f2f441775.png)

---

<div class="post-metadata">

### Author: ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)
#### Post date: [24 January 2021 09:11 UTC](https://igraph.discourse.group/t/group-nodes-in-igraph/601/2 "2021-01-24T09:11:49Z")

</div>

You can give `layout_as_bipartite` a try.

---

<div class="post-metadata">

### Author: ![gadepallivs](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/gadepallivs/32/439_2.png) [@gadepallivs](https://igraph.discourse.group/u/gadepallivs)
#### Post date: [24 January 2021 09:18 UTC](https://igraph.discourse.group/t/group-nodes-in-igraph/601/3 "2021-01-24T09:18:16Z")

</div>

That arranges the nodes in 2 rows. Is there a way to change that arrangement to columns ?  
What I did is use `layout_as_tree` and then create a graph object. Later, I accessed the x values and then assigned - x to the one group and then +x values for another group. Here is my [SO question](https://stackoverflow.com/questions/65583493/gather-nodes-based-on-group-information) .  
I have them separated, but was thinking if there may be more appropriate way to do this. I would like to have more control on assigning positions to the nodes.

---

<div class="post-metadata">

### Author: ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)
#### Post date: [24 January 2021 12:02 UTC](https://igraph.discourse.group/t/group-nodes-in-igraph/601/4 "2021-01-24T12:02:57Z")

</div>

What the bipartite layout does is that it finds an ordering of vertices within the two groups so as to minimize the number of edge crossings when both are arranged in a line.

You can try to build something on top of this:

- You can swap x and y coordinates to use rows instead of columns.
- You can manually stagger vertices instead of placing them on a line—this should still maintain few edge crossings.

---

<div class="post-metadata">

### Author: ![gadepallivs](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/gadepallivs/32/439_2.png) [@gadepallivs](https://igraph.discourse.group/u/gadepallivs)
#### Post date: [8 February 2021 16:00 UTC](https://igraph.discourse.group/t/group-nodes-in-igraph/601/5 "2021-02-08T16:00:45Z")

</div>

would mind to provide an example, I did not understand on how to swap x and y co-ordinates
