sankey_build_data | R Documentation |
Prepare data to be input into the networkD3 sankeyNetwork function.
sankey_build_data(data, colour_data)
data |
A tibble or dataframe with all categorical columns apart from the final column, which is numeric. Required input. |
colour_data |
A tibble or dataframe with variable 1 called name containing relevant categorical values and variable 2 called colour and containing hex codes (or colour names). Required input. |
A vector of labels.
library(dplyr)
plot_data <- tibble::tribble(
~state1, ~state2, ~value,
"Trees", "Grass", 5,
"Trees", "Wetland", 1,
"Grass", "Trees", 7,
"Grass", "Wetland", 1,
"Wetland", "Trees", 1,
"Wetland", "Grass", 2)
pal_data <- tibble::tribble(
~name, ~colour,
"Trees", "purple",
"Grass", "green",
"Wetland", "brown")
sankey_data <- sankey_build_data(
data = plot_data,
colour_data = pal_data)
units <- "ha"
networkD3::sankeyNetwork(Links = sankey_data$links, Nodes = sankey_data$nodes,
Source = "source_id", Target = "target_id", Value = "value",
NodeID = "name", colourScale = sankey_data$colour_scale,
fontSize = 14, fontFamily = "Arial", units = units)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.