sankeyD3 v0.3 . Based on networkD3 and d3-sankey.
# Installation
# install.packages('devtools')
devtools::install_github("fbreitwieser/sankeyD3")
# Run example site directly from Github
shiny::runGitHub("fbreitwieser/sankeyD3", subdir="inst/examples/shiny")
## Run it locally
library(sankeyD3)
# Based on http://bost.ocks.org/mike/sankey/
# Load energy projection data
URL <- paste0("https://cdn.rawgit.com/christophergandrud/networkD3/",
"master/JSONdata/energy.json")
Energy <- jsonlite::fromJSON(URL)
# Plot
sankeyNetwork(Links = Energy$links, Nodes = Energy$nodes, Source = "source",
Target = "target", Value = "value", NodeID = "name",
units = "TWh", fontSize = 12, nodeWidth = 30)
Use saveNetwork
to save a network to stand alone HTML file:
library(magrittr)
sankeyNetwork(Links = Energy$links, Nodes = Energy$nodes, Source = "source",
Target = "target", Value = "value", NodeID = "name",
units = "TWh", fontSize = 12, nodeWidth = 30) %>% saveNetwork(file = 'Net1.html')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.