Description Usage Arguments Source See Also Examples
Create a D3 JavaScript Sankey diagram
1 2 3 4 5 | sankeyNetwork(Links, Nodes, Source, Target, Value, NodeID, NodeGroup = NodeID,
LinkGroup = NULL, units = "",
colourScale = JS("d3.scaleOrdinal(d3.schemeCategory20);"), fontSize = 7,
fontFamily = NULL, nodeWidth = 15, nodePadding = 10, margin = NULL,
height = NULL, width = NULL, iterations = 32, sinksRight = TRUE)
|
Links |
a data frame object with the links between the nodes. It should
have 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 |
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 |
NodeGroup |
character string specifying the node groups in the
|
LinkGroup |
character string specifying the groups in the
|
units |
character string describing physical units (if any) for Value |
colourScale |
character string specifying the categorical colour scale for the nodes. See https://github.com/d3/d3/blob/master/API.md#ordinal-scales. |
fontSize |
numeric font size in pixels for the node text labels. |
fontFamily |
font family for the node text labels. |
nodeWidth |
numeric width of each node. |
nodePadding |
numeric essentially influences the width height. |
margin |
an integer or a named |
height |
numeric height for the network graph's frame area in pixels. |
width |
numeric width for the network graph's frame area in pixels. |
iterations |
numeric. Number of iterations in the diagramm layout for computation of the depth (y-position) of each node. Note: this runs in the browser on the client so don't push it too high. |
sinksRight |
boolean. If |
D3.js was created by Michael Bostock. See http://d3js.org/ and, more specifically for Sankey diagrams http://bost.ocks.org/mike/sankey/.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | ## Not run:
# Recreate Bostock Sankey diagram: http://bost.ocks.org/mike/sankey/
# Load energy projection data
URL <- paste0('https://cdn.rawgit.com/christophergandrud/networkD3/',
'master/JSONdata/energy.json')
energy <- jsonlite::fromJSON(URL)
# Plot
sankeyNetwork(Links = energy$links, Nodes = energy$nodes, Source = 'source',
Target = 'target', Value = 'value', NodeID = 'name',
units = 'TWh', fontSize = 12, nodeWidth = 30)
# Colour links
energy$links$energy_type <- sub(' .*', '',
energy$nodes[energy$links$source + 1, 'name'])
sankeyNetwork(Links = energy$links, Nodes = energy$nodes, Source = 'source',
Target = 'target', Value = 'value', NodeID = 'name',
LinkGroup = 'energy_type', NodeGroup = NULL)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.