v_sankey | R Documentation |
Create a Sankey Chart
v_sankey(
vc,
mapping = NULL,
data = NULL,
name = NULL,
...,
serie_id = NULL,
data_id = NULL
)
vc |
A chart initialized with |
mapping |
Default list of aesthetic mappings to use for chart. |
data |
Default dataset to use for chart. If not already
a |
name |
Name for the serie, only used for single serie (no |
... |
Additional parameters for the serie. |
data_id , serie_id |
ID for the data/serie, can be used to further customize the chart with |
A vchart()
htmlwidget
object.
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))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.