knitr::opts_chunk$set( collapse = TRUE, comment = "#>", warning = FALSE ) library(htmltools) library(sigmajs)
Below are the basics of the package.
sigmajs() function.sg_.sg_get_ are helpers that do not take a sigmajs object as input._p.%>%).The variable names must follow sigma.js convention.
Nodes must ideally include, at least:
id unique id of node, note that this does not have to be numericalsize size of nodecolor color of nodeThese are passed to sg_nodes. Note that sigma.js requires passing x and y, if omitted the function will randomly assign x and y positions.
Edges must include, at least:
id unique id of edgesource source of edgetarget target of edgesource and target refer to the nodes id
Remember to always follow the naming convention.
The package comes with two convenience functions to generate data, mainly to be used for testing.
sg_make_nodes to generate nodes, you can specify the number of nodes you want.sg_make_edges to generate edges based on the nodes, you can specify the number of edges you want.Above I state that you must ideally pass size and color to the nodes. I say "ideally" because, you actually can omit color if you then pass default color using sg_settings.
There a lot of settings to pass, see the official wiki for a list of all settings.
# generate data using convenience functions nodes <- sg_make_nodes() edges <- sg_make_edges(nodes) sigmajs() %>% sg_nodes(nodes, id, size, color) %>% sg_edges(edges, id, source, target)
Or as stated in the Settings section, you can omit size and color but you then must pass defaults using sg_settings.
sigmajs() %>% sg_nodes(nodes, id, size) %>% sg_edges(edges, id, source, target) %>% sg_settings(defaultNodeColor = "#c9423f") # pass default color
Browse the documentation to see how to give your graphs neat layouts, animate them, see how the package works with shiny and more.
tags$a( class = "btn btn-default", href = "layout.html", "Layouts ", tags$i( class = "fa fa-arrow-right" ) )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.