D3 JavaScript Network Graphs from R

Creates 'D3' 'JavaScript' network, tree, dendrogram, and Sankey graphs from 'R'.


D3 JavaScript Network Graphs from R

Development version: 0.4.9000 CRANVersion BuildStatus CRAN MonthlyDownloads CRANTotal Downloads

This README includes information on set up and a number of basic examples. For more information see the package's main page.

Usage

Here's an example of simpleNetwork:

library(networkD3)

# 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.7,
             colourScale = JS("d3.scaleOrdinal(d3.schemeCategory20);"))

Here's sankeyNetwork using a downloaded JSON data file:

# Recreate Bostock Sankey diagram: https://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)

Interacting with igraph

You can use igraph to create network graph data that can be plotted with networkD3. The igraph_to_networkD3 function converts igraph graphs to lists that work well with networkD3. For example:

# Load igraph
library(igraph)

# Use igraph to make the graph and find membership
karate <- make_graph("Zachary")
wc <- cluster_walktrap(karate)
members <- membership(wc)

# Convert to object suitable for networkD3
karate_d3 <- igraph_to_networkD3(karate, group = members)

# Create force directed network plot
forceNetwork(Links = karate_d3$links, Nodes = karate_d3$nodes, 
             Source = 'source', Target = 'target', NodeID = 'name', 
             Group = 'group')

Saving to an external file

Use saveNetwork to save a network to stand alone HTML file:

library(magrittr)

simpleNetwork(networkData) %>% saveNetwork(file = 'Net1.html')

Note

networkD3 began as a port of d3Network package to the htmlwidgets framework. d3Network is no longer supported.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("networkD3")

0.4.1 by Christopher Gandrud, 2 years ago


https://christophergandrud.github.io/networkD3/, https://github.com/christophergandrud/networkD3


Report a bug at https://github.com/christophergandrud/networkD3/issues


Browse source code at https://github.com/cran/networkD3


Authors: J.J. Allaire [aut] , Peter Ellis [ctb] , Christopher Gandrud [aut, cre] , Kevin Kuo [ctb] , B.W. Lewis [ctb] , Jonathan Owen [ctb] , Kenton Russell [aut] , Jennifer Rogers [ctb] , Charles Sese [ctb] , CJ Yetman [aut]


Documentation:   PDF Manual  


GPL (>= 3) license


Imports data.tree, htmlwidgets, igraph, jsonlite, magrittr

Suggests htmltools, tibble

Enhances knitr, shiny


Imported by BallMapper, BayesianNetwork, DataExplorer, EnrichIntersect, GREENeR, LUCIDus, MapperAlgo, NIMAA, OpenLand, RWsearch, ShinyBlock, UniprotR, carbonpredict, censuspyrID, citationchaser, compIndexBuilder, dextergui, mcdabench, richCluster, robin, scGOclust, vivainsights, wpa.

Suggested by MetaNet, MiscMetabar, PRA, TreatmentPatterns, covid19dbcand, dartR, dartR.base, data.tree, dogesr, drake, mums2, planr, rtemis, sfcr, stylo.


See at CRAN