Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add igraph to d3 converter #3

Closed
timelyportfolio opened this issue Aug 30, 2016 · 5 comments
Closed

add igraph to d3 converter #3

timelyportfolio opened this issue Aug 30, 2016 · 5 comments

Comments

@timelyportfolio
Copy link
Owner

timelyportfolio commented Aug 30, 2016

While talking with @ttriche on Twitter, I remembered a helpful function would be to convert igraph to a "standard" d3.js network. I have some preliminary code that will require testing and iteration.

@ttriche
Copy link

ttriche commented Aug 30, 2016

mine looks something like this (pulling out part of a protein-protein network):

# pull out CREBBP for discussion 
library(networkD3)
toD3 <- function(g) { 
  wc <- cluster_walktrap(g) 
  members <- membership(wc)
  igraph_to_networkD3(g, group=members)
}
plotForceNet <- function(g, ...) {
  stopifnot(is(g, "igraph"))
  with(toD3(g), 
       forceNetwork(Links=links, Nodes=nodes, 
                    Source="source", Target="target", 
                    NodeID="name", Group="group", 
                    zoom=TRUE, bounded=TRUE, ...))
}
CREBBP_sub <- induced_subgraph(mergedGraph, 
                               ego(mergedGraph, 1, 
                                   which(names(V(mergedGraph))=="CREBBP"))[[1]])
p <- plotForceNet(CREBBP_sub, fontSize=12, opacity=0.9, opacityNoHover=0.3)
saveNetwork(p, file="CREBBP.html") # uploaded to amazon S3

@timelyportfolio
Copy link
Owner Author

Thanks @ttriche. The networkd3::igraph_to_networkD3 works fairly well, but it makes some assumptions for the benefit of its particular use. I think the proposed code is a little more generic, but I'm not convinced. I have not tested with the member/group, so I will do that now to make sure it handles. After that, my next round of tests will be to plug in the converted to multiple examples.

@timelyportfolio
Copy link
Owner Author

Add layout if available to allow igraph layouts to be paired with d3.js. This will make for a very powerful combination supplementing d3.js with the igraph layouts, but interactivity will be tricky. Start with just adding x and y attributes and then go from there.

@timelyportfolio
Copy link
Owner Author

added attributes to the return value c200062

@timelyportfolio
Copy link
Owner Author

Going to close this for now, since I added d3_igraph, but I will very likely resurrect this especially given @thomasp85 work on tidygraph.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants