Learn R Programming

visNetwork (version 1.0.0)

visOptions: Network visualization general options

Description

Network visualization general options. For full documentation, have a look at visDocumentation.

Usage

visOptions(graph, width = NULL, height = NULL, highlightNearest = FALSE,
  nodesIdSelection = FALSE, selectedBy = NULL, autoResize = NULL,
  clickToUse = NULL, manipulation = NULL)

Arguments

graph
: a visNetwork object
width
: String. Default to "100%". The width of the network in pixels or as a percentage.
height
: String. Default to "100%". The height of the network in pixels or as a percentage.
highlightNearest
: Custom Option. Just a Boolean, or a named list. Default to false. Highlight nearest when clicking a node ? Not available for DOT and Gephi.
  • "enabled"
{ : Boolean. Default to false. Activated or not ?.} "degree"{ : Intege

item

  • nodesIdSelection
  • "values
  • "selected"
  • "style"
  • selectedBy
  • "values
  • "selected"
  • "style"
  • "multiple"
  • autoResize
  • clickToUse
  • manipulation

itemize

  • "variable"

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
nodes <- data.frame(id = 1:15, label = paste("Label", 1:15),
 group = sample(LETTERS[1:3], 15, replace = TRUE))

edges <- data.frame(from = trunc(runif(15)*(15-1))+1,
 to = trunc(runif(15)*(15-1))+1)
 
###################  
# highlight nearest
###################

visNetwork(nodes, edges) %>% visOptions(highlightNearest = TRUE)
visNetwork(nodes, edges) %>% visOptions(highlightNearest = list(enabled = TRUE, degree = 2))

# also when hover a node ?
visNetwork(nodes, edges) %>% visOptions(highlightNearest = list(enabled = TRUE, hover = TRUE))

##########################
# nodesIdSelection
##########################

visNetwork(nodes, edges) %>% 
 visOptions(highlightNearest = TRUE, nodesIdSelection = TRUE)

# add a default selected node ?
visNetwork(nodes, edges) %>% 
 visOptions(highlightNearest = TRUE, 
 nodesIdSelection = list(enabled = TRUE, selected = "1"))
 
# subset on id values ?
visNetwork(nodes, edges) %>% 
 visOptions(highlightNearest = TRUE, 
 nodesIdSelection = list(enabled = TRUE, 
   selected = "2",
   values = c(2:10)))
 
# some style
visNetwork(nodes, edges) %>% 
 visOptions(highlightNearest = TRUE, 
 nodesIdSelection = list(enabled = TRUE, style = 'width: 200px; height: 26px;
   background: #f8f8f8;
   color: darkblue;
   border:none;
   outline:none;'))   
 
##########################
# selectedBy
##########################

visNetwork(nodes, edges) %>% 
 visOptions(selectedBy = "group")
 
# add a default value ?
visNetwork(nodes, edges) %>% 
 visOptions(selectedBy = list(variable = "group", selected = "A"))

# subset on values ?
visNetwork(nodes, edges) %>% 
 visOptions(selectedBy = list(variable = "group", 
   selected = "C",
   values = c("A", "C")))
 
# add some style
visNetwork(nodes, edges) %>% 
 visOptions(selectedBy = list(variable = "group", style = 'width: 200px; height: 26px;
   background: #f8f8f8;
   color: darkblue;
   border:none;
   outline:none;'))
     
# can also be on new column
nodes$sample <- sample(c("sample 1", "sample 2"), nrow(nodes), replace = TRUE)
visNetwork(nodes, edges) %>% 
 visOptions(selectedBy = "sample")

# and with multiple groups ?
nodes$group <- sample(c("group 1", "group 2", "group 1, group 2, group 3"), 
 nrow(nodes), replace = TRUE)
 
visNetwork(nodes, edges) %>% 
 visOptions(selectedBy = list(variable = "group", multiple = TRUE))

Run the code above in your browser using DataLab