# How to use a different input to draw community polygons in igraph?

**URL:** <https://igraph.discourse.group/t/how-to-use-a-different-input-to-draw-community-polygons-in-igraph/484>\
**Category:** Usage\
**Tags:** R\
**Created:** [18 October 2020 11:37 UTC](https://igraph.discourse.group/t/how-to-use-a-different-input-to-draw-community-polygons-in-igraph/484 "2020-10-18T11:37:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![marmello77](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/marmello77/32/385_2.png) [@marmello77](https://igraph.discourse.group/u/marmello77)\
**Post date:** [18 October 2020 11:37 UTC](https://igraph.discourse.group/t/how-to-use-a-different-input-to-draw-community-polygons-in-igraph/484/1 "2020-10-18T11:37:55Z")

</div>

Could you please help me?

I love plotting networks with **igraph**. One nice feature is drawing **polygons around the communities** detected by a given algorithm.

When you use one of the community detection algorithms built in igraph, that’s pretty straightforward. Like in this example with a random bipartite graph:

```
library(igraph)
graph <- sample_bipartite(10, 10, p = 0.5)
graph
graph.lou = cluster_louvain(graph)
graph.lou$membership
length(graph.lou$membership)
plot(graph.lou, graph)

```

But how can I use another kind of input to draw those polygons?

For instance, I usually calculate modularity using the package **bipartite** , because it has other algorithms that are better suited for two-mode networks.

So I’m trying to use the output from bipartite as an input for drawing community polygons in igraph. As in the following example:

```
library(bipartite)
matrix <- as_incidence_matrix(graph)
matrix
matrix.bec = computeModules(matrix, method = "Beckett")
modules <- module2constraints(matrix.bec)
modules
length(modules)
plot(modules, graph)

```

From the output of the _computeModules_ function I’m able to extract a vector with **community memberships** using the _module2constraints_ function. When I try to use it as a plotting input, I get this error message:

```
Error in xy.coords(x, y, xlabel, ylabel, log) : 
  'x' and 'y' lengths differ

```

Is it possible to use this output from bipartite in igraph, so polygons are automatically drawn around the communities?

I’ve looked into the documentation, searched here in the forum and on StackOverflow, experimented some tricks, but found no solution.

Thank you very much!

---

<div class="post-metadata">

**Author:** ![Christian-T](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/christian-t/32/513_2.png) [@Christian-T](https://igraph.discourse.group/u/Christian-T)\
**Post date:** [14 July 2021 16:00 UTC](https://igraph.discourse.group/t/how-to-use-a-different-input-to-draw-community-polygons-in-igraph/484/2 "2021-07-14T16:00:39Z")

</div>

The info that is stored in _modules_ is not enough for the plot function. You need an object with the information which node belongs to which group. I wrote a quick’n’dirty solution, and I hope someone might come up with a function or a better solution:

```auto
graph.modules <- NULL
graph.modules$`1` <- which(modules=="1")
graph.modules$`2` <- which(modules=="2")
graph.modules$`3` <- which(modules=="3")
graph.modules$`4` <- which(modules=="4")
graph.modules

plot(graph, mark.groups=graph.modules)

```

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