Skip to contents

Relayout each nodegroup in a bipartite (Cnet) graph, experimental

Usage

relayout_nodegroups(
  cnet,
  repulse = 3.5,
  fix_set_nodes = TRUE,
  spread_labels = TRUE,
  nodegroups = NULL,
  add_edges = TRUE,
  edge_factor = 2,
  do_final_relayout = NULL,
  final_repulse = 3.5,
  ...
)

Arguments

cnet

igraph object with node layout already defined

repulse

numeric default 3.5, passed to relayout_with_qfr()

fix_set_nodes

logical default TRUE, whether to fix all nodes with nodeType=='Set' to prevent them from moving.

spread_labels

logical default TRUE, whether to apply spread_igraph_labels() after the relayout iterations are complete.

nodegroups

list default NULL, intended to pass a custom set of nodegroups. When NULL it uses get_cnet_nodeset().

...

additional arguments are passed to spread_igraph_labels()

Value

igraph object with updated layout.

Details

This function iteratively re-applies a layout function to each nodegroup in a graph, constraining the position of all other nodes for each iteration. Currently the layout uses relayout_with_qfr(), in future it may use any layout function.

The purpose is to "encourage" nodes in a nodegroup to become bundled together.

Strategy:

  • Each nodegroup is isolated, and relayout_with_qfr() is called on nodes in each nodegroup, while constraining all other nodes so they cannot move.

  • In theory, using the same repulse, the nodes would not move at all. Changing the repulse force could encourage nodes to stay together.

  • By default add_edges=TRUE which adds phantom edges to connect all nodes in a node group.

    • The edge weight is scaled down by the number of nodes.

    • These phantom edges are intended to help 'encourage' the nodegroup nodes to group together.

    • Otherwise, most layout algorithms are only focused on specific edge forces, and not secondary forces which are common in Cnet plots.

    • For example, nodes in a nodegroup all share the same network connections, however they are not otherwise attracted to each other in a network layout. In absence of any repulsive force, they would all be co-located. But with some repulsive force, they are repelled from each other, and sometimes end up radially positioned around the plot, and not grouped together.

    • The phantom edges add some minimal force for nodes to be grouped closer together, and are removed once the layout is complete.

  • As a final polishing step, do_final_relayout=TRUE enables a final round of global node layout, with final_repulse.

    • We observed that sometimes the nodegroups are too clumped, in a big circular "ball" due to the phantom edge process above. The final relayout is helpful to allow nodes to space out somewhat.

    • It may be helpful to pass niter to control the number of layout iterations in this final step. The default is 500.

Todo

Bonus points:

  • Determine if each nodegroup is "split" around another nodegroup. If so, iterate that nodegroup using varying 'repulse' or other strategies to attempt to minimize the issue.

Examples

cnet <- make_cnet_test();
ns <- get_cnet_nodeset(cnet)
# mark.groups: highlight just one nodegroup
# nodegroups: enables the edge_bundling to work properly
jam_igraph(cnet, mark.groups=ns["SetA,SetB"], nodegroups=ns,
   main="One nodegroup is split")


cnet2 <- relayout_nodegroups(cnet, nodegroups=ns["SetA,SetB"])
#> [1] 3
#> [1] 3
jam_igraph(cnet2, mark.groups=ns["SetA,SetB"], nodegroups=ns,
   main="This nodegroup is 'encouraged' to re-group")


cnet2 <- relayout_nodegroups(cnet, nodegroups=ns)
#> [1] 16
#> [1] 120
#> [1] 3
#> [1] 3
#> [1] 5
#> [1] 10
#> [1] 3
#> [1] 3
#> [1] 3
#> [1] 3
#> [1] 7
#> [1] 21
#> [1] 4
#> [1] 6
#> [1] 14
#> [1] 91
#> [1] 4
#> [1] 6
#> [1] 2
#> [1] 1
#> [1] 5
#> [1] 10
#> [1] 18
#> [1] 153
#> [1] 9
#> [1] 36
jam_igraph(cnet2, mark.groups=ns["SetA,SetB"], nodegroups=ns,
   main="Re-layout across all nodegroups")