Jean-Baptiste-Camps / stemmatology

Stemmatological Analysis of Textual Traditions
GNU General Public License v3.0
15 stars 3 forks source link

Network plotting: switching from `sna`+`network` to `igraph` ? #31

Closed Jean-Baptiste-Camps closed 6 years ago

Jean-Baptiste-Camps commented 6 years ago

I wonder whether to switch from sna (+network) to igraph for network plotting

Some reading:

Problems and solutions

For the moment, the problem with sna::gplot is that it does not scale graphics properly in R studio, and graphs have readability issues.

A side benefit seems to be that igraph has built-in tree objects and methods (such as layout=layout_as_tree, etc.).

NB: the default placement algorithm (modifiable) for sna is 'fruchtermanreigold', and for igraph, `` layout_nicely: a smart function that chooses a layouter based on the graph.''

Also, maybe graphViz could be an interesting solution. It seems quite used in the stemmatology community and has R implementations.

Performance

In terms of performance, I have run profiling on the following lines:

##network + SNA
myNetwork = as.network(edgelist, directed = FALSE, matrix.type = "edgelist")  #Important remark here : not specifying matrix.type = edgelist gave, occasionnaly, weird errors, mainly 'Erreur dans abs(x) : argument non numérique pour une fonction mathématique'... So, I am expliciting this option everywhere
  gplot(myNetwork, displaylabels, label = network.vertex.names(myNetwork), 
        gmode = "graph", boxed.labels = TRUE)#default mode: mode = "fruchtermanreingold", 

#igraph
  myNetwork = igraph::graph_from_edgelist(edgelist, directed = FALSE)
  plot(myNetwork)#, layout=layout_as_tree)#The default value is layout_nicely, 
  #a smart function that chooses a layouter based on the graph.

Result:

Graphics

In terms of graphics (in Rstudio, without reconfiguring the graphics interface)

SNA

snagplot

igraph

igraphplot

What do you think, @floriancafiero ? I am tempted to switch to igraph, which means some important changes in code and visualisation (as compared to what we've been doing until now).

Jean-Baptiste-Camps commented 6 years ago

Also, it seems that igraph as an easy way of setting edge length, and that would be useful for setting this length as a function of the number of disagreements in the stemmata, which I have been wanting to do since a long time now…

Jean-Baptiste-Camps commented 6 years ago

And for trees:

Current layout

stemma_sna

igraph

stemma_igraph

Jean-Baptiste-Camps commented 6 years ago

Ooops, apparently, I missed #27 ! You were suggesting other packages already.

Jean-Baptiste-Camps commented 6 years ago

Only issue with igraph is that we won't be able to set arbitrary edge lengths in stemmata (for instance, an edge length proportional to the number of disagreements). The way to do that would be to use a phylogenetic tree package…

Jean-Baptiste-Camps commented 6 years ago

Actually, there might be a workaround with igraph, but it includes coding a small layout modifying function to adjust coordinates. EDIT: implemented a basic function to do that.

Jean-Baptiste-Camps commented 6 years ago

Switched to igraph done for all graph plotting.