Layout

knitr::opts_chunk$set( collapse = TRUE, comment = "#>", warning = FALSE ) library(sigmajs)

Since v0.0.3 you can use any of the igraph layout algorithms, simply use sg_layout and pass the actual igraph layout to the function.

Static

# generate data using convenience functions nodes <- sg_make_nodes(50) edges <- sg_make_edges(nodes) sigmajs() %>% sg_nodes(nodes, id, size, color) %>% sg_edges(edges, id, source, target) %>% sg_layout(FALSE, igraph::layout_with_fr) # pass layout FUN

Force

You can also use the forceAtlas2 algorithm to layout your graphs, sg_force_start. The algorithm is relatively computationally expensive so it is good to stop it at some point sg_force_stop.

sigmajs() %>% sg_force_start() %>% # start sg_nodes(nodes, id, size, color) %>% sg_edges(edges, id, source, target) %>% sg_force_stop(5000) # stop after 5 seconds

There is also sg_get_layout if you only want to retrieve the x and y coordinates of your graph.