Description Usage Arguments Source Examples
View source: R/d3ForceNetwork.R
Create a D3 JavaScript force directed network graph.
1 2 3 4 5 6 | d3ForceNetwork(Links, Nodes, Source, Target, Value = NULL, NodeID, Group,
height = 600, width = 900, fontsize = 7, linkDistance = 50,
linkWidth = "function(d) { return Math.sqrt(d.value); }", charge = -120,
linkColour = "#666", opacity = 0.6, zoom = FALSE,
parentElement = "body", standAlone = TRUE, file = NULL,
iframe = FALSE, d3Script = "http://d3js.org/d3.v3.min.js")
|
Links |
a data frame object with the links between the nodes. It should
include the |
Nodes |
a data frame containing the node id and properties of the nodes.
If no ID is specified then the nodes must be in the same order as the Source
variable column in the |
Source |
character string naming the network source variable in the
|
Target |
character string naming the network target variable in the
|
Value |
character string naming the variable in the |
NodeID |
character string specifying the node IDs in the |
Group |
character string specifying the group of each node in the
|
height |
numeric height for the network graph's frame area in pixels. |
width |
numeric width for the network graph's frame area in pixels. |
fontsize |
numeric font size in pixels for the node text labels. |
linkDistance |
numeric or character string. Either numberic fixed
distance between the links in pixels (actually arbitrary relative to the
diagram's size). Or a JavaScript function, possibly to weight by
|
linkWidth |
numeric or character string. Can be a numeric fixed width in
pixels (arbitrary relative to the diagram's size). Or a JavaScript function,
possibly to weight by |
charge |
numeric value indicating either the strength of the node repulsion (negative value) or attraction (positive value). |
linkColour |
character string specifying the colour you want the link lines to be. Multiple formats supported (e.g. hexadecimal). |
opacity |
numeric value of the proportion opaque you would like the graph elements to be. |
zoom |
logical, whether or not to enable the ability to use the mouse scroll-wheel to zoom in and out of the graph. |
parentElement |
character string specifying the parent element for the
resulting svg network graph. This effectively allows the user to specify
where on the html page the graph will be placed. By default the parent
element is |
standAlone |
logical, whether or not to return a complete HTML document (with head and foot) or just the script. |
file |
a character string of the file name to save the resulting graph.
If a file name is given a standalone webpage is created, i.e. with a header
and footer. If |
iframe |
logical. If |
d3Script |
a character string that allows you to specify the location of the d3.js script you would like to use. The default is http://d3js.org/d3.v3.min.js. |
D3.js was created by Michael Bostock. See http://d3js.org/ and, more specifically for force directed networks https://github.com/mbostock/d3/wiki/Force-Layout.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #### Tabular data example.
# Load data
data(MisLinks)
data(MisNodes)
# Create graph
d3ForceNetwork(Links = MisLinks, Nodes = MisNodes, Source = "source",
Target = "target", Value = "value", NodeID = "name",
Group = "group", opacity = 0.4)
## Not run:
#### JSON Data Example
# Load data JSON formated data into two R data frames
library(RCurl)
MisJson <- getURL("http://bit.ly/1cc3anB")
MisLinks <- JSONtoDF(jsonStr = MisJson, array = "links")
MisNodes <- JSONtoDF(jsonStr = MisJson, array = "nodes")
# Create graph
d3ForceNetwork(Links = MisLinks, Nodes = MisNodes, Source = "source",
Target = "target", Value = "value", NodeID = "name",
Group = "group", opacity = 0.4)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.