18 Interactive Networks
18.1 visNetwork (interactive)
vis.js library; it uses
tidyverse piping: VisNetwork Docs.
–> The Vignette has clear worked-out examples: https://cran.r-project.org/web/packages/visNetwork/vignettes/Introduction-to-visNetwork.html
visNetwork documentation doesn’t provide the same level of explanation as the original, so it’s worth checking out the
vis.js documentation as well:
http://visjs.org/index.html In particular, the interactive examples are particularly useful for trying out different options. For example, you can test out physics options with this network configurator.
18.1.1 Minimum working example
Create a node data frame with a minimum one of column (must be called
id) with node names:
Create a separate data frame of edges with
Draw the network with
Add labels by adding a label column to
visNetwork can be very slow.
%>% visPhysics(stabilization = FALSE) starts rendering before the stabilization is complete, which does actually speed things up but allows you to see what’s happening, which makes a big difference in user experience. (It’s also fun to watch the network stabilize). Other performance tips are described here.
18.1.3 Helpful configuration tools
%>% visConfigure(enabled = TRUE) is a useful tool for configuring options interactively. Upon completion, click “generate options” for the code to reproduce the settings. More here (Note that changing options and then viewing them requires a lot of vertical scrolling in the browser. I’m not sure if anything can be done about this. If you have a solution, let me know!)
18.1.4 Coloring nodes
Add a column of actual color names to the nodes data frame:
18.1.5 Directed nodes (arrows)
18.1.6 Turn off the physics simulation
It’s much faster without the simulation. The nodes are randomly placed and can be moved around without affecting the rest of the network, at least in the case of small networks.
18.1.7 Grey out nodes far from selected (defined by “degree”)
(Click a node to see effect.)