Description Usage Arguments Source See Also Examples
Create a D3 JavaScript Sankey diagram
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | sankeyNetwork(Links, Nodes, Source, Target, Value, NodeID, NodeGroup = NodeID,
LinkGroup = NULL, NodePosX = NULL, NodeValue = NULL, NodeColor = NULL,
NodeFontColor = NULL, NodeFontSize = NULL, units = "",
colourScale = JS("d3.scaleOrdinal().range(d3.schemeCategory20)"),
fontSize = 7, fontFamily = NULL, fontColor = NULL, nodeWidth = 15,
nodePadding = 10, nodeStrokeWidth = 1, nodeCornerRadius = 0,
margin = NULL, title = NULL, numberFormat = ",.5g",
orderByPath = FALSE, highlightChildLinks = FALSE,
doubleclickTogglesChildren = FALSE, xAxisDomain = NULL, dragX = FALSE,
dragY = FALSE, height = NULL, width = NULL, iterations = 32,
zoom = FALSE, align = "justify", showNodeValues = TRUE,
linkType = "bezier", curvature = 0.5, linkColor = "#A0A0A0",
nodeLabelMargin = 2, linkOpacity = 0.5, linkGradient = FALSE,
nodeShadow = FALSE, scaleNodeBreadthsByString = FALSE,
xScalingFactor = 1, yOrderComparator = NULL)
|
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
|
NodePosX |
character specifying a column in the |
NodeValue |
character specifying a column in the |
NodeColor |
character specifying a column in the |
NodeFontColor |
character specifying a column in the |
NodeFontSize |
character specifying a column 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/mbostock/d3/wiki/Ordinal-Scales. |
fontSize |
numeric font size in pixels for the node text labels. |
fontFamily |
font family for the node text labels. |
fontColor |
font color for the node text labels. |
nodeWidth |
numeric width of each node. |
nodePadding |
numeric essentially influences the width height. |
nodeStrokeWidth |
numeric width of the stroke around nodes. |
nodeCornerRadius |
numeric Radius for rounded nodes. |
margin |
an integer or a named |
title |
character Title of plot, put in the upper-left corner of the Sankey |
numberFormat |
number format in toolstips - see https://github.com/d3/d3-format for options. |
orderByPath |
boolean Order the nodes vertically along a path - this layout only works well for trees where each node has maximum one parent. |
highlightChildLinks |
boolean Highlight all the links going right from a node or link. |
doubleclickTogglesChildren |
boolean Show/hide target nodes and paths to the left on double-click. Does not hide incoming links of target nodes, yet. |
xAxisDomain |
character[] If xAxisDomain is given, an axis with those value is added to the bottom of the plot. Only sensible when also NodeXPos are given. |
dragX |
boolean Allow moving nodes along the x-axis? |
dragY |
boolean Allow moving nodes along the y-axis? |
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. |
zoom |
logical value to enable ( |
align |
character Alignment of the nodes. One of 'right', 'left', 'justify', 'center', 'none'. If 'none', then the labels of the nodes are always to the right of the node. |
showNodeValues |
boolean Show values above nodes. Might require and increased node margin. |
linkType |
character One of 'bezier', 'l-bezier', 'trapezoid', 'path1' and 'path2'. |
curvature |
numeric Curvature parameter for bezier links - between 0 and 1. |
linkColor |
numeric Color of links. |
nodeLabelMargin |
numeric margin between node and label. |
linkOpacity |
numeric Opacity of links. |
linkGradient |
boolean Add a gradient to the links? |
nodeShadow |
boolean Add a shadow to the nodes? |
scaleNodeBreadthsByString |
Put nodes at positions relatively to string lengths - only work well currently with align='none' |
xScalingFactor |
numeric Scale the computed x position of the nodes by this value. |
yOrderComparator |
Order nodes on the y axis by a custom function instead of ascending or descending depth. |
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.