Description Usage Arguments Value Examples
Function to convert igraph graph to a list suitable for networkD3
1 | igraph_to_networkD3(g, group, what = "both")
|
g |
an |
group |
an object that contains node group values, for example, those
created with igraph's |
what |
a character string specifying what to return. If
|
A list of link and node data frames or only the link or node data frames.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | # 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')
## Not run:
# Example with data from data frame
# Load data
## Original data from http://results.ref.ac.uk/DownloadSubmissions/ByUoa/21
data('SchoolsJournals')
# Convert to igraph
SchoolsJournals <- graph.data.frame(SchoolsJournals, directed = FALSE)
# Remove duplicate edges
SchoolsJournals <- simplify(SchoolsJournals)
# Find group membership
wt <- cluster_walktrap(SchoolsJournals, steps = 6)
members <- membership(wt)
# Convert igraph to list for networkD3
sj_list <- igraph_to_networkD3(SchoolsJournals, group = members)
# Plot as a forceDirected Network
forceNetwork(Links = sj_list$links, Nodes = sj_list$nodes, Source = 'source',
Target = 'target', NodeID = 'name', Group = 'group',
zoom = TRUE, linkDistance = 200)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.