Package 'ggsankey'

Title: Sankey, Alluvial and Sankey Bump Plots
Description: A package that makes it easy to implement sankey, alluvial and sankey bump plots in ggplot2.
Authors: David Sjoberg
Maintainer: David Sjoberg <[email protected]>
License: MIT + file LICENSE
Version: 0.0.99999
Built: 2026-05-27 07:03:46 UTC
Source: https://github.com/davidsjoberg/ggsankey

Help Index


geom_alluvial

Description

Creates an alluvial plot which visualize flows between nodes. Each observation needs to have a 'x' aesthetic as well as a 'next_x' column which declares where that observation should flow. Also each observation should have a 'node' and a 'next_node' aesthetic which provide information about which group in the y-direction.

Usage

geom_alluvial(
  mapping = NULL,
  data = NULL,
  position = "identity",
  na.rm = FALSE,
  show.legend = NA,
  space = 0,
  width = 0.1,
  smooth = 8,
  inherit.aes = TRUE,
  ...
)

Arguments

mapping

provide you own mapping. both x and y need to be numeric.

data

provide you own data

position

change position

na.rm

remove missing values

show.legend

show legend in plot

space

space between nodes in the y-direction

width

width of nodes

smooth

how much smooth should the curve have? More means steeper curve.

inherit.aes

should the geom inherit aesthetics

...

other arguments to be passed to the geo

Value

ggplot layer


geom_alluvial_label

Description

Creates centered labels or text in nodes of your alluvial plot. Needs to have the exact same aesthetics as the call to 'geom_alluvial' to work.

Usage

geom_alluvial_text(
  mapping = NULL,
  data = NULL,
  position = "identity",
  na.rm = FALSE,
  show.legend = NA,
  space = 0,
  width = 0.1,
  inherit.aes = TRUE,
  ...
)

geom_alluvial_label(
  mapping = NULL,
  data = NULL,
  position = "identity",
  na.rm = FALSE,
  show.legend = NA,
  space = 0,
  width = 0.1,
  inherit.aes = TRUE,
  ...
)

Arguments

mapping

provide you own mapping. both x and y need to be numeric.

data

provide you own data

position

change position

na.rm

remove missing values

show.legend

show legend in plot

space

space between nodes in the y-direction

width

width of nodes

inherit.aes

should the geom inherit aesthetics

...

other arguments to be passed to the geo

Details

Other important arguments is; 'space' which proves the space between nodes in the y-direction; 'shift' which shifts nodes in the y-direction.

Value

ggplot layer


geom_sankey

Description

Creates a sankey plot which visualize flows between nodes. Each observation needs to have a 'x' aesthetic as well as a 'next_x' column which declares where that observation should flow. Also each observation should have a 'node' and a 'next_node' aesthetic which provide information about which group in the y-direction. By default each row of the data frame is counted to calculate the size of flows. A manual flow value can be added with the 'value' aesthetic.

Usage

geom_sankey(
  mapping = NULL,
  data = NULL,
  position = "identity",
  na.rm = FALSE,
  show.legend = NA,
  space = NULL,
  type = "sankey",
  width = 0.1,
  smooth = 8,
  inherit.aes = TRUE,
  ...
)

Arguments

mapping

provide you own mapping. both x and y need to be numeric.

data

provide you own data

position

change position

na.rm

remove missing values

show.legend

show legend in plot

space

space between nodes in the y-direction

type

either 'sankey' or 'alluvial'

width

width of nodes

smooth

how much smooth should the curve have? More means steeper curve.

inherit.aes

should the geom inherit aesthetics

...

other arguments to be passed to the geom

Value

ggplot layer

Aesthetics

geom_sankey understand the following aesthetics (required aesthetics are in bold):

- **x0** - **y0** - **a** - **b** - **angle** - m1 - m2 - color - fill - size - linetype - alpha - lineend


geom_sankey_bump

Description

Creates an alluvial plot which visualize flows between nodes. Each observation needs to have a 'x' aesthetic as well as a 'next_x' column which declares where that observation should flow. Also each observation should have a 'node' and a 'next_node' aesthetic which provide information about which group in the y-direction.

Usage

geom_sankey_bump(
  mapping = NULL,
  data = NULL,
  position = "identity",
  na.rm = FALSE,
  show.legend = NA,
  smooth = 8,
  type = "sankey",
  inherit.aes = TRUE,
  ...
)

Arguments

mapping

provide you own mapping. both x and y need to be numeric.

data

provide you own data

position

change position

na.rm

remove missing values

show.legend

show legend in plot

smooth

how much smooth should the curve have? More means steeper curve.

type

either 'sankey' or 'alluvial'

inherit.aes

should the geom inherit aesthetics

...

other arguments to be passed to the geo

Details

Other important arguments is; 'space' which proves the space between nodes in the y-direction; 'shift' which shifts nodes in the y-direction.

Value

ggplot layer


geom_sankey_label

Description

Creates centered labels or text in nodes of your sankey plot. Needs to have the exact same aesthetics as the call to 'geom_sankey' to work.

Usage

geom_sankey_label(
  mapping = NULL,
  data = NULL,
  position = "identity",
  na.rm = FALSE,
  show.legend = NA,
  space = NULL,
  type = "sankey",
  width = 0.1,
  inherit.aes = TRUE,
  ...
)

geom_sankey_text(
  mapping = NULL,
  data = NULL,
  position = "identity",
  na.rm = FALSE,
  show.legend = NA,
  space = NULL,
  type = "sankey",
  width = 0.1,
  inherit.aes = TRUE,
  ...
)

Arguments

mapping

provide you own mapping. both x and y need to be numeric.

data

provide you own data

position

change position

na.rm

remove missing values

show.legend

show legend in plot

space

space between nodes in the y-direction

type

Either 'sankey' which centers around the x axis or 'alluvial' which starts at y = 0 and moves upward.

width

width of nodes

inherit.aes

should the geom inherit aesthetics

...

other arguments to be passed to the geom

Value

ggplot layer


make_long

Description

Prepares a 'wide' data frame into a format that 'geom_sankey' or 'geom_alluvial' understands. Useful to show flows between dimensions in dataset.

Usage

make_long(.df, ..., value = NULL)

Arguments

.df

a data frame

...

unquoted columnnames of df that you want to include in the plot.

value

if each row have a weight this weight could be kept by providing column name of weight.

Value

a longer data frame


sankey_themes

Description

Minimal themes for sankey, alluvial and sankey bump plots

Usage

theme_sankey(
  base_size = 11,
  base_family = "",
  base_line_size = base_size/22,
  base_rect_size = base_size/22
)

theme_alluvial(
  base_size = 11,
  base_family = "",
  base_line_size = base_size/22,
  base_rect_size = base_size/22
)

theme_sankey_bump(
  base_size = 11,
  base_family = "",
  base_line_size = base_size/22,
  base_rect_size = base_size/22
)

Arguments

base_size

base font size, given in pts.

base_family

base font family

base_line_size

base size for line elements

base_rect_size

base size for rect elements