Skip to content

Instantly share code, notes, and snippets.

@timelyportfolio
Created February 24, 2015 16:33
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save timelyportfolio/0aa9e782baf29d5c7e48 to your computer and use it in GitHub Desktop.
Save timelyportfolio/0aa9e782baf29d5c7e48 to your computer and use it in GitHub Desktop.
igraph in DiagrammeR

In response to this tweet

@riannone @abresler @timelyportfolio this popped into my head last week, how hard would it be to dump an igraph or graphNEL into diagrammeR?

— Tim Triche, Jr. (@timtriche) February 24, 2015
<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>

I made this little Gist. It illustrates one way to git an igraph into DiagrammeR using grViz. One way to use igraph with mermaid can be seen in this Gist R ( igraph + DiagrammeR + pipeR +htmltools ) + JS ( mermaid.js + d3.js + dagre-d3.js ).

Full attribute customization will probably not be possible with these two methods. For this full set of functionality, Rich Iannone's work with a data.frame (think get.data.frame from igraph) will provide some amazing results.

library(igraph)
library(DiagrammeR)
tf <- tempfile()
write.graph(
graph.famous("Tetrahedron")
,tf
,format="dot"
)
grViz(
readLines(tf)
)
library(htmltools)
html_print(tagList(
lapply(
c("neato","circo","twopi")
,function(engine){ grViz( readLines(tf) , engine = engine ) }
)
))
unlink(tf)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment