sankey: Sankey diagram

View source: R/sankey.R

sankeyR Documentation

Sankey diagram

Description

Creates Sankey diagram from edgelist data.frame.

Usage

sankey(
  df,
  source.column = "source",
  target.column = "target",
  value.column = "value",
  sort.nodes = c(TRUE, FALSE),
  text.align = c("outside", "inside"),
  margin.proportion = 0.2,
  edge.color = c("path", "input", "output", "none"),
  color.scheme = c("Spectral", names(d3po::color.schemes)),
  width = NULL,
  height = NULL,
  viewer = c("internal", "external", "browser")
)

Arguments

df

data.frame containing edgelist data.

source.column

Name of column containing source nodes. Defaults to "source".

target.column

Name of column containing target nodes. Defaults to "target".

value.column

Name of column containing edge values. Defaults to "value".

sort.nodes

Boolean indicating whether to let sankey.js to sort nodes. Defaults to TRUE. If FALSE, nodes will be ordered as they appear in df.

text.align

Alignment of node labels. Defaults to "outside".

margin.proportion

Proportion of image to devote to margins on both left and right side. Only effective when text.align is "outside". Defaults to 0.2, must be between 0 and 0.5.

edge.color

Method of coloring edges. The value "path" will create a gradient between two nodes. Defaults to "path".

color.scheme

Color scheme to use in visualization. See color.schemes for more details.

width

Desired width for output widget.

height

Desired height for output widget.

viewer

"internal" to use the RStudio internal viewer pane for output; "external" to display in an external RStudio window; "browser" to display in an external browser.

Details

Utilizes a script similar to https://observablehq.com/@d3/sankey-diagram adapted to work with r2d3.

Value

A d3 object as returned by r2d3.

Examples

data(energy)

sankey(energy)


tkmckenzie/d3po documentation built on June 2, 2022, 2:41 p.m.