Version 0.1
This is a port of Christopher Gandrud's d3Network package to the htmlwidgets framework.
To install and use you'll need to install this package and two of it's dependencies from GitHub:
library(devtools)
install_github(c('rstudio/htmltools',
'ramnathv/htmlwidgets',
'christophergandrud/networkD3'))
Here's an example of simpleNetwork
:
# Create fake data
src <- c("A", "A", "A", "A", "B", "B", "C", "C", "D")
target <- c("B", "C", "D", "J", "E", "F", "G", "H", "I")
networkData <- data.frame(src, target)
# Plot
simpleNetwork(networkData)
Here's forceNetwork
:
# Load data
data(MisLinks)
data(MisNodes)
# Plot
forceNetwork(Links = MisLinks, Nodes = MisNodes, Source = "source",
Target = "target", Value = "value", NodeID = "name",
Group = "group", opacity = 0.4,
colourScale = "d3.scale.category20b()")
Here's sankeyNetwork
using a downloaded JSON data file:
# Load energy projection data
library(RCurl)
URL <- "https://raw.githubusercontent.com/christophergandrud/networkD3/master/JSONdata/energy.json"
Energy <- getURL(URL, ssl.verifypeer = FALSE)
# Convert to data frame
EngLinks <- JSONtoDF(jsonStr = Energy, array = "links")
EngNodes <- JSONtoDF(jsonStr = Energy, array = "nodes")
# Plot
sankeyNetwork(Links = EngLinks, Nodes = EngNodes, Source = "source",
Target = "target", Value = "value", NodeID = "name",
fontsize = 12, nodeWidth = 30)
Use saveNetwork
to save a network to stand alone HTML file:
library(magrittr)
simpleNetwork(networkData) %>% saveNetwork(file = 'Net1.html')