Reduce empty space in ggnet2 network plot

364 Views Asked by At

I'm plotting the network graph pictured below using R and GGally::ggnet2.

You can see that there are several independent clusters disconnected from each other and these are quite spread out leaving a lot of empty space on the figure. Is it possible to make these clusters closer to each other thus making better use of the space?

enter image description here

Code to reproduce:

# Get datafile
wget https://www.dropbox.com/s/h4kt2fw1j4hdw3a/matrix.tsv

R
library(GGally)
library(network)

mat <- read.table('matrix.tsv')
net <- network(mat)
ggnet2(net, size= 1)
1

There are 1 best solutions below

2
On

Trying different layouts might prove effective:

library(GGally)
library(network)

ggnet2(net,
       size= 1,
       mode = "kamadakawai")

enter image description here

or you can experiment with the parameters of a specific layout using the layout.par argument

ggnet2(net,
       size= 1,
       mode = "fruchtermanreingold",
       layout.par = list(repulse.rad = 100,
                         area = 1000))

enter image description here

for a complete list of options see ?sna::gplot.layout

Too find a pleasing layout you will need to experiment a bit with the options since they depend on the graph. To cite a part of the help ?sna::gplot.layout:

Vertex layouts for network visualization pose a difficult problem – there is no single, “good” layout algorithm, and many different approaches may be valuable under different circumstances.

set.seed(1234)
ggnet2(net,
       size= 1,
       mode = "fruchtermanreingold",
       layout.par = list(repulse.rad = 300,
                         area = 1200))

enter image description here

Another option is using visNetwork and after finding a good initial layout manually moving some vertices