GeomSankeysegment {ggsankeyfier} | R Documentation |
Sankey edges (flows)
Description
geom_sankeysegment()
draws a straight line between two connected nodes,
geom_sankeyedge()
draws a ribbon between nodes following a Bezier curved path.
If you combine the edges with geom_sankeynode()
, make sure that both use the
same position
object.
Usage
GeomSankeysegment
geom_sankeysegment(
mapping = NULL,
data = NULL,
stat = "sankeyedge",
position = "sankey",
na.rm = FALSE,
show.legend = NA,
order = c("ascending", "descending", "as_is"),
width = "auto",
align = c("bottom", "top", "center", "justify"),
h_space = "auto",
v_space = 0,
nudge_x = 0,
nudge_y = 0,
split_nodes = FALSE,
split_tol = 0.001,
direction = c("forward", "backward"),
inherit.aes = TRUE,
...
)
GeomSankeyedge
geom_sankeyedge(
mapping = NULL,
data = NULL,
stat = "sankeyedge",
position = "sankey",
na.rm = FALSE,
show.legend = NA,
slope = 0.5,
ncp = 100,
width = "auto",
align = c("bottom", "top", "center", "justify"),
order = c("ascending", "descending", "as_is"),
h_space = "auto",
v_space = 0,
nudge_x = 0,
nudge_y = 0,
split_nodes = FALSE,
split_tol = 0.001,
direction = c("forward", "backward"),
inherit.aes = TRUE,
...
)
Arguments
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
The statistical transformation to use on the data for this
layer, either as a |
position |
Position adjustment, either as a string naming the adjustment
(e.g. |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
order |
A |
width |
Width of the node ( |
align |
A |
h_space |
Horizontal space between split nodes ( |
v_space |
Vertical space between nodes ( |
nudge_x , nudge_y |
Horizontal and vertical adjustment to nudge items by. Can be useful for offsetting labels. |
split_nodes |
A |
split_tol |
When the relative node size (resulting source and destination edges) differs more than this fraction, the node will be displayed as two separate bars. |
direction |
One of |
inherit.aes |
If |
... |
Other arguments passed on to |
slope |
Slope parameter ( |
ncp |
Number of control points on the Bezier curve that forms the edge. Larger numbers will result in smoother curves, but cost more computational time. Default is 100. |
Format
An object of class GeomSankeysegment
(inherits from GeomSegment
, Geom
, ggproto
, gg
) of length 4.
An object of class GeomSankeyedge
(inherits from GeomSankeysegment
, GeomSegment
, Geom
, ggproto
, gg
) of length 7.
Details
This ggplot2
layer connects between paired nodes via a Bezier curve. The width
of the curve is determined by its y
aesthetic. It will be attempted to keep the
width of the curve constant along its curved path, for the targeted graphics device.
When the aspect ratio of the graphics device is altered after the plot is generated,
the aspect ratio maybe off. In that case render the plot again.
Value
Returns a ggplot2::layer()
which can be added to a ggplot2::ggplot()
Aesthetics
geom_sankeysegment()
and geom_sankeyedge()
understand the following
aesthetics (required aesthetics are in bold)
-
x
: Works for variables on a discrete scale. Might work for continuous variables but is not guaranteed. This variable is used to distinguish between stages in the Sankey diagram on the x axis. -
y
: A continuous variable representing the width of the edges in a Sankey diagram. -
group
: A discrete variable used for grouping edges to nodes in each stage. Essentially it is an identifier for the nodes. -
connector
: Indicates which side of an edge is reflected by the corresponding record. Should be one of"from"
or"to"
. -
edge_id
: A unique identifier value for each edge. This identifier is used to link specific"from"
and"to"
records in an edge (flow). fill: see
vignette("ggplot2-specs", "ggplot2")
colour: see
vignette("ggplot2-specs", "ggplot2")
linetype: see
vignette("ggplot2-specs", "ggplot2")
linewidth: see
vignette("ggplot2-specs", "ggplot2")
alpha: A variable to control the opacity of an element.
waist: A variable to control the width of an edge in between two nodes. Small values will create a hour glass shape, whereas large values will produce an apple shape.
Author(s)
Pepijn de Vries
Examples
library(ggplot2)
data("ecosystem_services")
ggplot(ecosystem_services_pivot1, aes(x = stage, y = RCSES, group = node,
connector = connector, edge_id = edge_id,
fill = node)) +
geom_sankeynode(v_space = "auto") +
geom_sankeyedge(v_space = "auto")