GeomSankeynode | R Documentation |
In a Sankey diagram nodes are depicted as stacked bars, possibly with
vertical spacing between them. Use geom_sankeynode()
to add nodes to
your Sankey diagram. If you combine the nodes with geom_sankeyedge()
,
make sure that both use the same position
object.
GeomSankeynode
geom_sankeynode(
mapping = NULL,
data = NULL,
stat = "sankeynode",
position = "sankey",
na.rm = FALSE,
show.legend = NA,
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,
...
)
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?
|
width |
Width of the node ( |
align |
A |
order |
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 |
An object of class GeomSankeynode
(inherits from GeomBar
, GeomRect
, Geom
, ggproto
, gg
) of length 6.
This ggplot2
layer depicts the size of all connected edges as a bar. The height of
of each bar is determined by the sum of y
aesthetic in each group
. When the sum of edges
that flow to a bar differ more than split_tol
compared to the edges that flow from the
same node, a vertical split is introduced in the node.
Returns a ggplot2::layer()
which can be added to a ggplot2::ggplot()
geom_sankeynode()
understands 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.
Pepijn de Vries
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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.