sankeyNetwork
From networkD3 v0.2.13
by Christopher Gandrud
Create a D3 JavaScript Sankey diagram
Create a D3 JavaScript Sankey diagram
Usage
sankeyNetwork(Links, Nodes, Source, Target, Value, NodeID, NodeGroup = NodeID, LinkGroup = NULL, units = "", colourScale = JS("d3.scale.category20()"), fontSize = 7, fontFamily = NULL, nodeWidth = 15, nodePadding = 10, margin = NULL, height = NULL, width = NULL, iterations = 32)
Arguments
- Links
- a data frame object with the links between the nodes. It should
have include the
Source
andTarget
for each link. An optionalValue
variable can be included to specify how close the nodes are to one another. - 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 theLinks
data frame. Currently only grouping variable is allowed. - Source
- character string naming the network source variable in the
Links
data frame. - Target
- character string naming the network target variable in the
Links
data frame. - Value
- character string naming the variable in the
Links
data frame for how far away the nodes are from one another. - NodeID
- character string specifying the node IDs in the
Nodes
. data frame. Must be 0-indexed. - NodeGroup
- character string specifying the node groups in the
Nodes
. Used to color the nodes in the network. - LinkGroup
- character string specifying the groups in the
Links
. Used to color the links in the network. - 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/mbostock/d3/wiki/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
list
/vector
of integers for the plot margins. If using a namedlist
/vector
, the positionstop
,right
,bottom
,left
are valid. If a single integer is provided, then the value will be assigned to the right margin. Set the margin appropriately to accomodate long text labels. - 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.
Source
D3.js was created by Michael Bostock. See http://d3js.org/ and, more specifically for Sankey diagrams http://bost.ocks.org/mike/sankey/.
See Also
Examples
## 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)
Community examples
Looks like there are no examples yet.