This README includes information on set up and a number of basic examples. For more information see the package's main page.
Here's an example of
# Create fake datasrc <- 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)# PlotsimpleNetwork(networkData)
# Load datadata(MisLinks)data(MisNodes)# PlotforceNetwork(Links = MisLinks, Nodes = MisNodes, Source = "source",Target = "target", Value = "value", NodeID = "name",Group = "group", opacity = 0.4,colourScale = "d3.scale.category20b()")
sankeyNetwork using a downloaded JSON data file:
# Recreate Bostock Sankey diagram:# Load energy projection dataURL <- paste0("","master/JSONdata/energy.json")Energy <- jsonlite::fromJSON(URL)# PlotsankeyNetwork(Links = Energy$links, Nodes = Energy$nodes, Source = "source",Target = "target", Value = "value", NodeID = "name",units = "TWh", fontSize = 12, nodeWidth = 30)
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 igraphlibrary(igraph)# Use igraph to make the graph and find membershipkarate <- make_graph("Zachary")wc <- cluster_walktrap(karate)members <- membership(wc)# Convert to object suitable for networkD3karate_d3 <- igraph_to_networkD3(karate, group = members)# Create force directed network plotforceNetwork(Links = karate_d3$links, Nodes = karate_d3$nodes,Source = 'source', Target = 'target', NodeID = 'name',Group = 'group')
saveNetwork to save a network to stand alone HTML file:
library(magrittr)simpleNetwork(networkData) %>% saveNetwork(file = 'Net1.html')
sankeyNetworkshould now work with
tbl_dflink and node data frames. Thanks to @mexindian for suggesting.
Add resize to sankeyNetwork for flexdashboard. Thanks to Kenton Russell for adding.
Fixed a bug where
Target labels were not properly concatenated
sankeyNetwork tooltips. Thanks to Tuija Sonkkila for reporting.
igraph_to_networkD3 so that it now handles more general weight
names. Thanks to Maurits Evers for reporting.
sankeyNetwork generate errors if data
does not appear to be zero-indexed. Thanks to Peter Meissner for prompting this
Bug fix for
igraph_to_networkD3 so that it now accepts the value attribute.
Thanks to Louis Goddard.
Bug fix for
diagonalNetwork when using hierarchical lists with singular
connections. Thanks to @RohdeK.
Fix viewbox position when rerendered in shiny. Thanks to @RohdeK.
iterations argument to
sankeyNetwork, which adjusts the y-axis
positioning. Thanks to @giko45.
Added the function
igraph_to_networkD3 to convert an
igraph class object
to a list that can be used with networkD3.
Fixed a bug where
linkColour was not actually passed to the widget for
radialNetwork. Thanks to Pierre Formont.
forceNetwork now allows you to supply a vector of colours to the
linkColourargument. This enables the user to highlight links to specific
nodes. Thanks to Garth Tarr.
Minor documentation improvements.
LinkGroup parameters to
sankeyNetwork so links
can be colourised. Thanks to Edwin de Jonge.
fontFamily is now applied to legends in
forceNetwork. Thanks to Casey
Improved bounding behaviour with
forceNetwork. Now bounds both the links and
nodes. Thanks to Koba Khitalishvili.
sankeyNetwork fully supports cycles
sankeyNetwork gets same responsive sizing and better fitting introduced
in 0.2.4 for
sankeyNetwork gets same full margin control introduced
in 0.2.4 for
chordDiagramto show directed relationships among entities.
More robust margin argument for
for a single value or specification of
Responsive sizing using the
viewBox attribute of
radialNetwork should allow for fitting in the container with no fiddling.
Internal improvements to reduce dependencies: no longer depends on RCurl, plyr, and rjson.
Using jsonlite makes JSONtoDF obsolete with the
All Github data links now use the CDN link from rawgit, so the examples should be more inline with Github raw policies.
Removes forced font family in favor of inherited from css or specified
Fixes issue with backslashes in the label for links.
Puts unicode right arrow in the tooltip. Adds argument to specify units for the tooltip label.
Handles cycles by updating this forked repo: https://github.com/soxofaan/d3-plugin-captain-sankey.
Makes assumptions that
Source is column 1 and
Target is column 2 if
Fixed an issue with
forceNetwork on Firefox. Thanks to @agoldst.
Fixed an issue where
forceNetwork node size would not return to
default after mouseover. Thanks to Pascal Pernot.
dendroNetwork to create hierarchical cluster network diagrams
treeNetwork is DEPRECATED.
Placed functionality from
radialNetwork. The new
radialNetwork function has the same functionality, but has been renamed to be
more accurately descriptive and avoid confusion with
diagonalNetwork, which creates tree network diagrams using diagonal
instead of radial nodes.
Thanks to Jonathan Owen.
clickAction argument to
forceNetwork to allow the user to
Thanks to Peter Ellis.
bounded argument to
forceNetwork to allow the user to create a
bounding box for the plot. See http://bl.ocks.org/mbostock/1129492.
Thanks to Charles Sese.
fontFamily argument to
treeNetwork. Thanks to Peter Ellis.
opacityNoHover argument to
forceNetwork to set the opacity of node
labels when nodes are not hovered over. Thanks to Peter Ellis.
## Version 0.1.7
JS from htmlwidgets, to make it easier for users to pass arbitrary
JS to more arguments.
Other internal code and documentation improvements.
fontSizeused for all functions rather than
fontsize. Thank you to @Hunter-Github for spotting this inconsistency.
## Version 0.1.5
forceNetwork gains three new arguments.
legend allows you to add a node colour legend.
Nodesize allow you to vary node radius by
Thank you to Charles Sese for these additions.
## Version 0.1.3
zoom argument added to
forceNetwork to allow zooming.
Thanks to @timelyportfolio.
Enhanced flexibility when using data frames manipulated with dplyr/data.table. Thanks to Kevin Kuo.
treeNetwork added allowing the user to create tree networks. Thanks to
Upgrade to d3.js version 3.5.2.
colourScale argument added to
sankeyNetwork to allow
the user to change the node colour scale.