0

I'm using a tripartite graph to visualize the overlapping club memberships among selected students in a given class, but since the output looks quite "long," I am wondering if there's a way to rotate this graph to put "Class" on top, the more numerous "Club" layer in the middle, and the "student" layer on the bottom?

Below is my code for this. It will be really appreciated if someone could share their thoughts on this.

require(igraph)
df <- read.csv2(text="Class;Club;Student
Class;Club 1;Student1
Class;Club 2;Student2
Class;Club 3;Student2
Class;Club 4;Student1
Class;Club 5;Student1
Class;Club 6;Student3
Class;Club 7;Student4
Class;Club 8;Student4
Class;Club 9;Student4
Class;Club 10;Student4")

mat <- as.matrix(df)

g <- graph_from_edgelist(rbind(mat[,1:2], mat[,2:3]), directed = F)

l <- layout_with_sugiyama(g, ceiling(match(V(g)$name, m)/nrow(m)))

plot(g, layout=-l$layout[,2:1])
Chris T.
  • 1,699
  • 7
  • 23
  • 45
  • I am unclear as to why you used `layout=-l$layout[,2:1])` If you simply use `plot(g, layout=l$layout)` You will get the orientation that you described. – G5W Jul 10 '19 at 00:23
  • @G5W, using `plot(g, layout=l$layout)` only reverse the direction of plot horizontally, while my desired output is a vertical layout with the "Class" level at the top. – Chris T. Jul 10 '19 at 02:41

0 Answers0