Sankey diagram from a data frame of directed links. Node names are derived
automatically from the unique values in the source and target columns;
no separate node list is required.
Usage
draw_sankey(
links,
orient = "horizontal",
node_width = NULL,
node_gap = NULL,
node_align = NULL,
title = NULL,
palette = NULL,
link_color = "source",
link_opacity = 0.45,
margins = NULL,
label_font_size = 12,
theme = NULL,
width = NULL,
height = NULL,
element_id = NULL,
filename = NULL
)Arguments
- links
data.frame: Directed links with columns
source(Character),target(Character), andvalue(Numeric).- orient
Optional Character {"horizontal", "vertical"}: Flow direction.
- node_width
Optional Numeric
[0, Inf): Node rectangle width in pixels.- node_gap
Optional Numeric
[0, Inf): Vertical gap between nodes in pixels.- node_align
Optional Character {"justify", "left", "right"}: Node alignment within each column.
- title
Optional Character: Chart title.
- palette
Optional Character: Node color palette — a single color string or a character vector that overrides the theme palette for this chart.
- link_color
Character {"source", "target", "gradient"} or a color: How ribbons are colored.
"source", the default, gives each ribbon the color of the node it leaves, which is what lets a reader follow one source across the diagram.- link_opacity
Numeric
[0, 1]: Ribbon opacity. Below 1 so that crossing ribbons blend rather than hide one another.- margins
Optional named list or numeric: Space around the plotting box, as any of
left,right,top,bottomin pixels or as a CSS width. Sides left unnamed are derived from the labels: a node's label is drawn to its right, so the last column needs room or its labels are clipped. Set them explicitly when preparing a static export, where the exact canvas is known.- label_font_size
Numeric: Node label font size in pixels. Also what the derived margins are estimated from.
- theme
Optional Theme: Theme override.
- width
Optional Character or Numeric: Widget width.
- height
Optional Character or Numeric: Widget height.
- element_id
Optional Character: Explicit DOM element ID for the widget container.
NULLlets htmlwidgets generate one.- filename
Optional Character: If provided, save the widget to this file via
save_drawing().
Examples
links <- data.frame(
source = c("A", "A", "B", "C"),
target = c("B", "C", "D", "D"),
value = c(8, 4, 6, 3)
)
draw_sankey(links)