networkD3 v0.4

0

Monthly downloads

0th

Percentile

D3 JavaScript Network Graphs from R

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

Readme

D3 JavaScript Network Graphs from R

Version 0.3 CRAN Version Build Status CRAN Monthly Downloads CRAN Total 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.4,
             colourScale = JS("d3.scaleOrdinal(d3.schemeCategory20);"))

Here's sankeyNetwork using a downloaded JSON data file:

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

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.

Functions in networkD3

Name Description
MisNodes Les Miserables character nodes
SchoolsJournals Edge list of REF (2014) journal submissions for Politics and International Relations
as.radialNetwork Convert an R hclust or dendrogram object into a radialNetwork list.
chordNetwork Create Reingold-Tilford Tree network diagrams.
chordNetworkOutput Shiny bindings for networkD3 widgets
networkD3-package Tools for Creating D3 Network Graphs from R
radialNetwork Create Reingold-Tilford Tree network diagrams.
sankeyNetwork Create a D3 JavaScript Sankey diagram
forceNetwork Create a D3 JavaScript force directed network graph.
igraph_to_networkD3 Function to convert igraph graph to a list suitable for networkD3
saveNetwork Save a network graph to an HTML file
simpleNetwork Function for creating simple D3 JavaScript force directed network graphs.
JS Create character strings that will be evaluated as JavaScript
MisLinks Les Miserables character links
diagonalNetwork Create Reingold-Tilford Tree network diagrams.
dendroNetwork Create hierarchical cluster network diagrams.
No Results!

Last month downloads

Details

Type Package
Date 2017-03-18
URL https://CRAN.R-project.org/package=networkD3
BugReports https://github.com/christophergandrud/networkD3/issues
License GPL (>= 3)
LazyData true
RoxygenNote 6.0.1
NeedsCompilation no
Packaged 2017-03-18 15:59:43 UTC; cgandrud
Repository CRAN
Date/Publication 2017-03-18 17:31:09 UTC

Include our badge in your README

[![Rdoc](http://www.rdocumentation.org/badges/version/networkD3)](http://www.rdocumentation.org/packages/networkD3)