Learn R Programming

visNetwork (version 1.0.0)

visIgraphLayout: Use a igraph layout for compute coordinates & fast rendering

Description

Use a igraph layout for compute coordinates and fast rendering. This function affect x and y coordinates to nodes data.frame using a igraph layout, and then render network faster with no stabilization. We set some options as : visNodes(physics = FALSE) & visEdges(smooth = FALSE) & visPhysics(stabilization= FALSE), but you can overwrite them using arguments or by add another call after visIgraphLayout

Usage

visIgraphLayout(graph, layout = "layout_nicely", physics = FALSE,
  smooth = FALSE, type = "square", randomSeed = NULL,
  layoutMatrix = NULL, ...)

Arguments

graph
: a visNetwork object
layout
: Character Name of igraph layout function to use. Default to "layout_nicely"
physics
: Boolean. Default to FALSE. Enabled physics on nodes ?
smooth
: Boolean. Default to FALSE. Use smooth edges ?
type
: Character Type of scale from igrah to vis.js. "square" (defaut) render in a square limit by height. "full" use width and height to scale in a rectangle.
randomSeed
: Number. The nodes are randomly positioned initially. This means that the settled result is different every time. If you provide a random seed manually, the layout will be the same every time.
layoutMatrix
: in case of layout = 'layout.norm'. the 'layout' argument (A matrix with two or three columns, the layout to normalize)
...
: Adding arguments to layout function

See Also

visNodes for nodes options, visEdges for edges options, visGroups for groups options, visLegend for adding legend, visOptions for custom option, visLayout & visHierarchicalLayout for layout, visPhysics for control physics, visInteraction for interaction, visNetworkProxy & visFocus & visFit for animation within shiny, visDocumentation, visEvents, visConfigure ...

Examples

Run this code
nnodes <- 200
nnedges <- 400

nodes <- data.frame(id = 1:nnodes)
edges <- data.frame(from = sample(1:nnodes, nnedges, replace = T), 
                   to = sample(1:nnodes, nnedges, replace = T))

# with defaut layout
visNetwork(nodes, edges) %>% 
 visIgraphLayout() %>%
 visNodes(size = 10)

# use full space
visNetwork(nodes, edges) %>% 
 visIgraphLayout(type = "full") %>%
 visNodes(size = 10)

# in circle ?
visNetwork(nodes, edges) %>% 
 visIgraphLayout(layout = "layout_in_circle") %>%
 visNodes(size = 10) %>%
 visOptions(highlightNearest = list(enabled = T, hover = T), 
   nodesIdSelection = T)
 
# keep physics with smooth curves ?
visNetwork(nodes, edges) %>% 
 visIgraphLayout(physics = TRUE, smooth = TRUE) %>%
 visNodes(size = 10)

# fix radomSeed to keep position
visNetwork(nodes, edges) %>% 
 visIgraphLayout(randomSeed = 123) %>%
 visNodes(size = 10)
 
visNetwork(nodes, edges) %>% 
 visIgraphLayout(randomSeed = 123) %>%
 visNodes(size = 10)

Run the code above in your browser using DataLab