Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

graph

Add nodes and edges


Description

Add nodes and edges to a sigmajs graph.

Usage

sg_nodes(sg, data, ...)

sg_edges(sg, data, ...)

sg_edges2(sg, data)

sg_nodes2(sg, data)

Arguments

sg

An object of class sigmajsas intatiated by sigmajs.

data

Data.frame (or list) of nodes or edges.

...

Any column name, see details.

Details

nodes: Must pass id (unique), size and color. If color is omitted than specify defaultNodeColor in sg_settings otherwise nodes will be transparent. Ideally nodes also include x and y, if they are not passed then they are randomly generated, you can either get these coordinates with sg_get_layout or sg_layout.

edges: Each edge also must include a unique id as well as two columns named source and target which correspond to node ids. If an edges goes from or to an id that is not in node id.

Value

A modified version of the sg object.

Functions

  • Functions ending in 2 take a list like the original sigma.js JSON.

  • Other functions take the arguments described above.

Note

node also takes a SharedData.

Examples

nodes <- sg_make_nodes()
edges <- sg_make_edges(nodes)

sg <- sigmajs() %>%
  sg_nodes(nodes, id, label, size, color) %>%
  sg_edges(edges, id, source, target) 
  
sg # no layout

# layout
sg %>% 
  sg_layout()

# directed graph
edges$type <- "arrow" # directed

# omit color
sigmajs() %>%
  sg_nodes(nodes, id, label, size) %>%
  sg_edges(edges, id, source, target, type) %>% 
  sg_settings(defaultNodeColor = "#141414")
  
# all source and target are present in node ids
all(c(edges$source, edges$target) %in% nodes$id)

sigmajs

Interface to 'Sigma.js' Graph Visualization Library

v0.1.5
MIT + file LICENSE
Authors
John Coene [aut, cre, cph] (<https://orcid.org/0000-0002-6637-4107>)
Initial release
2020-06-17

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.