Reputation: 1
Doing a sample, I am trying to make my undirected graph (used igraph) into an interactive one. I get the result that is the picture URL below my code. Whenever I take my "CzechCorruption data frame to the "simpleNetwork" function, it does not give me the same result as it does in igraph. It does not show the same visualization. How can I do that?
library (igraph)
library (networkd3)
CzechCorruption <- read.csv('CZECH_CORRUPTION.csv', header = T)
Cnetwork <- as.matrix(read.csv('CZECH_CORRUPTION.csv', header =T, row.names = 1))
g <- graph.adjacency(Cnetwork, mode = "undirected", weighted = TRUE)
plot(g, layout = layout_with_kk, vertex.label.cex = 0.75, edge.width=E(g)$weight)
p <- simpleNetwork(CzechCorruption, height ="200px", width = "200px", Source = 1, Target=2, fontSize =18, linkColour ="#777", nodeColour="#F47E5E", opacity = 0.7, zoom = T)
p
All in all, I want my graph that I depicted as an undirected graph utilizing the igraph library to convert successfully in networkd3. Suggestions? This is in R.
Upvotes: 0
Views: 536
Reputation: 37661
This is provided by the igraph_to_networkD3
. Here is the example given in the documentation.
library(igraph)
library(networkD3)
# 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')
Upvotes: 1