knitr::opts_chunk$set( collapse = TRUE, comment = "#>", warning = FALSE ) library(htmltools) library(sigmajs)
Below are the basics of the package.
- All graphs must be initialised with the
- All the functions of the package start with
- Functions starting in
sg_get_are helpers that do not take a
sigmajsobject as input.
- All proxies end in
- Functions are pipe-friendly (
The variable names must follow sigma.js convention.
Nodes must ideally include, at least:
idunique id of node, note that this does not have to be numerical
sizesize of node
colorcolor of node
These are passed to
sg_nodes. Note that sigma.js requires passing
y, if omitted the function will randomly assign x and y positions.
Edges must include, at least:
idunique id of edge
sourcesource of edge
targettarget of edge
target refer to the nodes
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_nodesto generate nodes, you can specify the number of nodes you want.
sg_make_edgesto generate edges based on the nodes, you can specify the number of edges you want.
Above I state that you must ideally pass
color to the nodes. I say "ideally" because, you actually can omit
color if you then pass default color using
There a lot of settings to pass, see the official wiki for a list of all settings.
Your first graphs
# 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
color but you then must pass defaults using
sigmajs() %>% sg_nodes(nodes, id, size) %>% sg_edges(edges, id, source, target) %>% sg_settings(defaultNodeColor = "#c9423f") # pass default color
tags$a( class = "btn btn-default", href = "layout.html", "Layouts ", tags$i( class = "fa fa-arrow-right" ) )