# NOT RUN {
# 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)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab