Skip to content

fbreitwieser/sankeyD3

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sankeyD3 - Sankey Network Graphs in R and Shiny

sankeyD3 v0.3 Build Status. Based on networkD3 and d3-sankey.

image

Installation and Usage

# 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)

Saving to an external file

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')

Features

  • Uses D3 v4
  • Adds option numberFormat, default being ",.5g" (see , fixes christophergandrud/networkD3#147)
  • Adds option NodePosX, fixes christophergandrud/networkD3#108
  • Adds option to force node ordering to be alphabetical along a path (only works well with trees with one parent for each node, but might fix christophergandrud/networkD3#153)
  • Zooming
  • Dragging both horizontally and vertically
  • Adds option showNodeValues to show node values above nodes
  • Adds option nodeCornerRadius for rounded nodes
  • Adds option title for titles in the upper-right corner of the plot
  • Adds _hover event that is fired every second
  • Adds option doubleclickTogglesChildren to hide children/downstram nodes
  • Adds option xScalingFactor to scale width between nodes
  • Adds option xAxisDomain to make an x-axis
  • Added option linkGradient to make link a gradient (when LinkGroup is not defined)
  • Added option linkColor to specify link color
  • Added option linkOpacity to specify opacity of link
  • Added option nodeShadow to add drop shadow
  • Added option nodeLabelMargin to specify the distance between label and node