2

I'm trying to plot a bipartite graph, but with two columns; the function manual states that layout_as_bipartite() "Minimize[s] edge-crossings in a simple two-row (or column) layout for bipartite graphs." Trying with the example, I can only get two row graphs:

library(igraph)
library(dplyr)
# Random bipartite graph
inc <- matrix(sample(0:1, 50, replace = TRUE, prob=c(2,1)), 10, 5)
g <- graph_from_incidence_matrix(inc)
plot(g, layout = layout_as_bipartite,
     vertex.color=c("green","cyan")[V(g)$type+1])

# Two columns
g %>%
  add_layout_(as_bipartite()) %>%
  plot()
Elio Diaz
  • 566
  • 2
  • 19

1 Answers1

5

It appears that layout_as_bipartite only does rows, not columns, but it is easy to just modify the resulting layout. The layout is simply X-Y coordinates for the nodes, so to change from rows to columns, just switch X and Y.

LO = layout_as_bipartite(g)
LO = LO[,c(2,1)]
plot(g, layout = LO, vertex.color=c("green","cyan")[V(g)$type+1])

Bipartite with Columns

G5W
  • 36,531
  • 10
  • 47
  • 80
  • I have a similar question posted [here](https://stackoverflow.com/questions/65989711/arrange-nodes-at-specific-location). For my data, I had to do a bit differently, but when I tried to use your approach, I get incorrect dimensions. Wondering if you can answer. Thank you – user5249203 Feb 15 '21 at 21:01
  • @user5249203 Sorry, I am not a shiny user. – G5W Feb 15 '21 at 23:31