# Creating a graph between nodes based on their common neighbour

**URL:** https://igraph.discourse.group/t/creating-a-graph-between-nodes-based-on-their-common-neighbour/409
**Category:** Usage
**Tags:** R
**Created:** [16 August 2020 02:52 UTC](https://igraph.discourse.group/t/creating-a-graph-between-nodes-based-on-their-common-neighbour/409 "2020-08-16T02:52:11Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Asimbikas\_Das](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/asimbikas_das/32/301_2.png) [@Asimbikas\_Das](https://igraph.discourse.group/u/Asimbikas_Das)
#### Post date: [16 August 2020 02:52 UTC](https://igraph.discourse.group/t/creating-a-graph-between-nodes-based-on-their-common-neighbour/409/1 "2020-08-16T02:52:11Z")

</div>

How to create a graph between nodes based on their common neighbour (or connection). Suppose, A is connected to B, B is connected to C. Then how to connect A-C and produce a graph, as B is common for both.

---

<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: [16 August 2020 06:34 UTC](https://igraph.discourse.group/t/creating-a-graph-between-nodes-based-on-their-common-neighbour/409/2 "2020-08-16T06:34:51Z")

</div>

You can use `connect.neighborhood` to add the A-C connection to the existing graph.

The operation you describe is called _graph power_ as it’s related to powers of the adjacency matrix.

If you _only_ want A-C, but not A-B and B-C, then get the (sparse) adjacency matrix, take its 2nd power, then convert it back to a graph.

---

<div class="post-metadata">

### Author: ![vtraag](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/vtraag/32/38_2.png) [@vtraag](https://igraph.discourse.group/u/vtraag)
#### Post date: [20 August 2020 08:42 UTC](https://igraph.discourse.group/t/creating-a-graph-between-nodes-based-on-their-common-neighbour/409/3 "2020-08-20T08:42:31Z")

</div>

You could also use `cocitation` or `bibcoupling` as an alternative. Note that those functions return matrices, which you can convert back into a graph:

```auto
G2 = graph_from_adjacency_matrix(cocitation(G), mode="undirected")

```

where `G` is the original graph of course.
