#### Tabular data example.
# Load data
data(MisLinks)
data(MisNodes)
# Create graph
forceNetwork(Links = MisLinks, Nodes = MisNodes, Source = "source",
Target = "target", Value = "value", NodeID = "name",
Group = "group", opacity = 0.4, zoom = TRUE)
# Create graph with legend and varying node radius
forceNetwork(Links = MisLinks, Nodes = MisNodes, Source = "source",
Target = "target", Value = "value", NodeID = "name",
Nodesize = "size",
radiusCalculation = "Math.sqrt(d.nodesize)+6",
Group = "group", opacity = 0.4, legend = TRUE)
#### JSON Data Example
# Load data JSON formated data into two R data frames
library(RCurl)
# Create URL. paste0 used purely to keep within line width.
URL <- paste0("https://raw.githubusercontent.com/christophergandrud/",
"networkD3/master/JSONdata/miserables.json")
MisJson <- getURL(URL)
MisLinks <- JSONtoDF(jsonStr = MisJson, array = "links")
MisNodes <- JSONtoDF(jsonStr = MisJson, array = "nodes")
# Create graph
forceNetwork(Links = MisLinks, Nodes = MisNodes, Source = "source",
Target = "target", Value = "value", NodeID = "name",
Group = "group", opacity = 0.4)
# Create graph with zooming
forceNetwork(Links = MisLinks, Nodes = MisNodes, Source = "source",
Target = "target", Value = "value", NodeID = "name",
Group = "group", opacity = 0.4, zoom = TRUE)
# Create a bounded graph
forceNetwork(Links = MisLinks, Nodes = MisNodes, Source = "source",
Target = "target", Value = "value", NodeID = "name",
Group = "group", opacity = 0.4, bounded = TRUE)
# Create graph with node text faintly visible when no hovering
forceNetwork(Links = MisLinks, Nodes = MisNodes, Source = "source",
Target = "target", Value = "value", NodeID = "name",
Group = "group", opacity = 0.4, bounded = TRUE,
opacityNoHover = TRUE)
# Create graph with alert pop-up when a node is clicked. You're
# unlikely to want to do exactly this, but you might use
# Shiny.onInputChange() to allocate d.XXX to an element of input
# for use in a Shiny app.
MyClickScript <- 'alert("You clicked " + d.name + " which is in row " +
(d.index + 1) + " of your original R data frame");'
forceNetwork(Links = MisLinks, Nodes = MisNodes, Source = "source",
Target = "target", Value = "value", NodeID = "name",
Group = "group", opacity = 1, zoom = F, bounded = T,
clickAction = MyClickScript)
Run the code above in your browser using DataLab