Create a Sankey Chart
v_sankey.RdCreate a Sankey Chart
Usage
v_sankey(
vc,
mapping = NULL,
data = NULL,
name = NULL,
...,
serie_id = NULL,
data_id = NULL
)Arguments
- vc
A chart initialized with
vchart().- mapping
Default list of aesthetic mappings to use for chart.
- data
Default dataset to use for chart. If not already a
data.frame, it will be coerced to withas.data.frame.- name
Name for the serie, only used for single serie (no
color/fillaesthetic supplied).- ...
Additional parameters for the serie.
- data_id, serie_id
ID for the data/serie, can be used to further customize the chart with
v_specs().
Value
A vchart() htmlwidget object.
Examples
library(vchartr)
# Basic Sankey Chart
vchart(energy_sankey) %>%
v_sankey(aes(target, source, value = value))
# Some options
vchart(energy_sankey) %>%
v_sankey(
aes(target, source, value = value),
nodeAlign = "left",
nodeGap = 8,
nodeWidth = 10,
minNodeHeight = 4,
link = list(
state = list(
hover = list(
fillOpacity = 1
)
)
)
)
# With data as tree structure
titanic <- as.data.frame(Titanic)
vchart(titanic) %>%
v_sankey(aes(
lvl1 = Class,
lvl2 = Sex,
lvl3 = Age,
lvl4 = Survived,
value = Freq
))
# Only one level
titanic_class <- titanic %>%
aggregate(data = ., Freq ~ Class + Survived, FUN = sum)
vchart(titanic_class) %>%
v_sankey(aes(Survived, Class, value = Freq))