igraph_to_networkD3: Function to convert igraph graph to a list suitable for...

Description Usage Arguments Value Examples

View source: R/utils.R

Description

Function to convert igraph graph to a list suitable for networkD3

Usage

1
igraph_to_networkD3(g, group, what = "both")

Arguments

g

an igraph class graph object

group

an object that contains node group values, for example, those created with igraph's membership function.

what

a character string specifying what to return. If what = 'links' or what = 'nodes' only the links or nodes are returned as data frames, respectively. If what = 'both' then both data frames will be return in a list.

Value

A list of link and node data frames or only the link or node data frames.

Examples

 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
## Not run: 
# Load igraph
library(igraph)

# 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)

jrdnmdhl/networkD3 documentation built on May 20, 2019, 10:44 a.m.