Title: | Interface to 'Sigma.js' Graph Visualization Library |
---|---|
Description: | Interface to 'sigma.js' graph visualization library including animations, plugins and shiny proxies. |
Authors: | John Coene [aut, cre, cph] , Markus Voge [aut] |
Maintainer: | John Coene <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.5 |
Built: | 2024-11-09 03:07:22 UTC |
Source: | https://github.com/johncoene/sigmajs |
Scale color by node size.
sg_scale_color(sg, pal)
sg_scale_color(sg, pal)
sg |
An object of class |
pal |
Vector of color. |
A modified version of the sg
object.
nodes <- sg_make_nodes() edges <- sg_make_edges(nodes, 20) sigmajs() %>% sg_nodes(nodes, id, size) %>% sg_scale_color(pal = c("red", "blue"))
nodes <- sg_make_nodes() edges <- sg_make_edges(nodes, 20) sigmajs() %>% sg_nodes(nodes, id, size) %>% sg_scale_color(pal = c("red", "blue"))
Implementation of forceAtlas2.
sg_force(sg, ...) sg_force_start(sg, ...) sg_force_stop(sg, delay = 5000) sg_force_restart_p(proxy, ..., refresh = TRUE) sg_force_restart(sg, data, delay, cumsum = TRUE) sg_force_start_p(proxy, ..., refresh = TRUE) sg_force_stop_p(proxy) sg_force_kill_p(proxy) sg_force_config_p(proxy, ...)
sg_force(sg, ...) sg_force_start(sg, ...) sg_force_stop(sg, delay = 5000) sg_force_restart_p(proxy, ..., refresh = TRUE) sg_force_restart(sg, data, delay, cumsum = TRUE) sg_force_start_p(proxy, ..., refresh = TRUE) sg_force_stop_p(proxy) sg_force_kill_p(proxy) sg_force_config_p(proxy, ...)
sg |
An object of class |
... |
Any parameter, see official documentation. |
delay |
Milliseconds after which the layout algorithm should stop running. |
proxy |
An object of class |
refresh |
Whether to refresh the graph after node is dropped, required to take effect. |
data |
|
cumsum |
Whether to compute the cumulative sum of the delay. |
The delay helps for build dynamic visualisations where nodes and edges do not appear all at the same time.
How the delay works depends on the cumsum
parameter. if TRUE
the function computes the cumulative sum
of the delay to effectively add each row one after the other: delay is thus applied at each row (number of seconds to wait
before the row is added *since the previous row*). If FALSE
this is the number of milliseconds to wait before the node or
edge is added to the visualisation; delay
is used as passed to the function.
Their first arguments, either sg
or proxy
.
sg_force
, sg_force_start
starts the forceAtlas2 layout
sg_force_stop
stops the forceAtlas2 layout after a delay
milliseconds
sg_force_restart_p
proxy to re-starts (kill
then start
) the forceAtlas2 layout, the options you pass to this function are applied on restart. If forceAtlas2 has not started yet it is launched.
sg_force_start_p
proxy to start forceAtlas2.
sg_force_stop_p
proxy to stop forceAtlas2.
sg_force_kill_p
proxy to ompletely stops the layout and terminates the assiociated worker. You can still restart it later, but a new worker will have to initialize.
sg_force_config_p
proxy to set configurations of forceAtlas2.
sg_force_restart
Restarts (kills then starts) forceAtlas2 at given delay.
nodes <- sg_make_nodes(50) edges <- sg_make_edges(nodes, 100) sigmajs() %>% sg_nodes(nodes, id, label, size) %>% sg_edges(edges, id, source, target) %>% sg_force() %>% sg_force_stop() # stop force after 5 seconds
nodes <- sg_make_nodes(50) edges <- sg_make_edges(nodes, 100) sigmajs() %>% sg_nodes(nodes, id, label, size) %>% sg_edges(edges, id, source, target) %>% sg_force() %>% sg_force_stop() # stop force after 5 seconds
A graph where the nodes are characters in "Les Miserables" updated from its first encoding by Professor Donald Knuth, as part of the Stanford Graph Base (SGB)
lesmis_edges
lesmis_edges
An igraph object with 181 nodes and 4 variables
source
abbreviation of character name
target
abbreviation of character name
id
unique edge id
label
edge label
https://github.com/MADStudioNU/lesmiserables-character-network
A graph where the nodes are characters in "Les Miserables" updated from its first encoding by Professor Donald Knuth, as part of the Stanford Graph Base (SGB)
lesmis_igraph
lesmis_igraph
An igraph object with 181 nodes and 1589 edges
id
abbreviation of character name
label
character name
color
random color
https://github.com/MADStudioNU/lesmiserables-character-network
A graph where the nodes are characters in "Les Miserables" updated from its first encoding by Professor Donald Knuth, as part of the Stanford Graph Base (SGB)
lesmis_nodes
lesmis_nodes
An igraph object with 181 nodes and 2 variables
id
abbreviation of character name
label
character name
https://github.com/MADStudioNU/lesmiserables-character-network
Read nodes and edges to add to the graph. Other proxy methods to add data to a graph have to add nodes and edges one by one, thereby draining the browser, this method will add multiple nodes and edges more efficiently.
sg_read_nodes_p(proxy, data, ...) sg_read_edges_p(proxy, data, ...) sg_read_exec_p(proxy)
sg_read_nodes_p(proxy, data, ...) sg_read_edges_p(proxy, data, ...) sg_read_exec_p(proxy)
proxy |
An object of class |
data |
A |
... |
any column. |
The proxy
object.
sg_read_nodes_p
read nodes.
sg_read_edges_p
read edges.
sg_read_exec_p
send read nodes and edges to JavaScript front end.
library(shiny) ui <- fluidPage( actionButton("add", "add nodes & edges"), sigmajsOutput("sg") ) server <- function(input, output, session){ nodes <- sg_make_nodes() edges <- sg_make_edges(nodes) output$sg <- renderSigmajs({ sigmajs() %>% sg_nodes(nodes, id, label, color, size) %>% sg_edges(edges, id, source, target) %>% sg_layout() }) i <- 10 observeEvent(input$add, { new_nodes <- sg_make_nodes() new_nodes$id <- as.character(as.numeric(new_nodes$id) + i) i <<- i + 10 ids <- 1:(i) new_edges <- data.frame( id = as.character((i * 2 + 15):(i * 2 + 29)), source = as.character(sample(ids, 15)), target = as.character(sample(ids, 15)) ) sigmajsProxy("sg") %>% sg_force_kill_p() %>% sg_read_nodes_p(new_nodes, id, label, color, size) %>% sg_read_edges_p(new_edges, id, source, target) %>% sg_read_exec_p() %>% sg_force_start_p() %>% sg_refresh_p() }) } if (interactive()) shinyApp(ui, server)
library(shiny) ui <- fluidPage( actionButton("add", "add nodes & edges"), sigmajsOutput("sg") ) server <- function(input, output, session){ nodes <- sg_make_nodes() edges <- sg_make_edges(nodes) output$sg <- renderSigmajs({ sigmajs() %>% sg_nodes(nodes, id, label, color, size) %>% sg_edges(edges, id, source, target) %>% sg_layout() }) i <- 10 observeEvent(input$add, { new_nodes <- sg_make_nodes() new_nodes$id <- as.character(as.numeric(new_nodes$id) + i) i <<- i + 10 ids <- 1:(i) new_edges <- data.frame( id = as.character((i * 2 + 15):(i * 2 + 29)), source = as.character(sample(ids, 15)), target = as.character(sample(ids, 15)) ) sigmajsProxy("sg") %>% sg_force_kill_p() %>% sg_read_nodes_p(new_nodes, id, label, color, size) %>% sg_read_edges_p(new_edges, id, source, target) %>% sg_read_exec_p() %>% sg_force_start_p() %>% sg_refresh_p() }) } if (interactive()) shinyApp(ui, server)
Read nodes and edges by batch with a delay.
sg_read_delay_nodes_p(proxy, data, ..., delay) sg_read_delay_edges_p(proxy, data, ..., delay) sg_read_delay_exec_p(proxy, refresh = TRUE)
sg_read_delay_nodes_p(proxy, data, ..., delay) sg_read_delay_edges_p(proxy, data, ..., delay) sg_read_delay_exec_p(proxy, refresh = TRUE)
proxy |
An object of class |
data |
A |
... |
any column. |
delay |
Column name of containing batch identifier. |
refresh |
Whether to refresh the graph after each batch ( |
Add nodes and edges with sg_read_delay_nodes_p
and sg_read_delay_edges_p
then execute (send to JavaScript end) with sg_read_delay_exec_p
.
The proxy
object.
library(shiny) ui <- fluidPage( actionButton("add", "add nodes & edges"), sigmajsOutput("sg") ) server <- function(input, output, session){ output$sg <- renderSigmajs({ sigmajs() }) observeEvent(input$add, { nodes <- sg_make_nodes(50) nodes$batch <- c( rep(1000, 25), rep(3000, 25) ) edges <- data.frame( id = 1:80, source = c( sample(1:25, 40, replace = TRUE), sample(1:50, 40, replace = TRUE) ), target = c( sample(1:25, 40, replace = TRUE), sample(1:50, 40, replace = TRUE) ), batch = c( rep(1000, 40), rep(3000, 40) ) ) %>% dplyr::mutate_all(as.character) sigmajsProxy("sg") %>% sg_force_start_p() %>% sg_read_delay_nodes_p(nodes, id, color, label, size, delay = batch) %>% sg_read_delay_edges_p(edges, id, source, target, delay = batch) %>% sg_read_delay_exec_p() %>% sg_force_stop_p() }) } if (interactive()) shinyApp(ui, server)
library(shiny) ui <- fluidPage( actionButton("add", "add nodes & edges"), sigmajsOutput("sg") ) server <- function(input, output, session){ output$sg <- renderSigmajs({ sigmajs() }) observeEvent(input$add, { nodes <- sg_make_nodes(50) nodes$batch <- c( rep(1000, 25), rep(3000, 25) ) edges <- data.frame( id = 1:80, source = c( sample(1:25, 40, replace = TRUE), sample(1:50, 40, replace = TRUE) ), target = c( sample(1:25, 40, replace = TRUE), sample(1:50, 40, replace = TRUE) ), batch = c( rep(1000, 40), rep(3000, 40) ) ) %>% dplyr::mutate_all(as.character) sigmajsProxy("sg") %>% sg_force_start_p() %>% sg_read_delay_nodes_p(nodes, id, color, label, size, delay = batch) %>% sg_read_delay_edges_p(edges, id, source, target, delay = batch) %>% sg_read_delay_exec_p() %>% sg_force_stop_p() }) } if (interactive()) shinyApp(ui, server)
Read nodes and edges into your graph, with or without a delay.
sg_read_nodes(sg, data, ..., delay) sg_read_edges(sg, data, ..., delay) sg_read_exec(sg, refresh = TRUE)
sg_read_nodes(sg, data, ..., delay) sg_read_edges(sg, data, ..., delay) sg_read_exec(sg, refresh = TRUE)
sg |
An object of class |
data |
Data.frame (or list) of nodes or edges. |
... |
Any column name, see details. |
delay |
Column name containing delay in milliseconds. |
refresh |
Whether to refresh the |
A modified version of the sg
object.
sg_read_nodes
read nodes.
sg_read_edges
read edges.
sg_read_exec
send read nodes and edges to JavaScript front end.
nodes <- sg_make_nodes(50) nodes$batch <- c( rep(1000, 25), rep(3000, 25) ) edges <- data.frame( id = 1:80, source = c( sample(1:25, 40, replace = TRUE), sample(1:50, 40, replace = TRUE) ), target = c( sample(1:25, 40, replace = TRUE), sample(1:50, 40, replace = TRUE) ), batch = c( rep(1000, 40), rep(3000, 40) ) ) %>% dplyr::mutate_all(as.character) sigmajs() %>% sg_force_start() %>% sg_read_nodes(nodes, id, label, color, size, delay = batch) %>% sg_read_edges(edges, id, source, target, delay = batch) %>% sg_force_stop(4000) %>% sg_read_exec() %>% sg_button("read_exec", "Add nodes & edges")
nodes <- sg_make_nodes(50) nodes$batch <- c( rep(1000, 25), rep(3000, 25) ) edges <- data.frame( id = 1:80, source = c( sample(1:25, 40, replace = TRUE), sample(1:50, 40, replace = TRUE) ), target = c( sample(1:25, 40, replace = TRUE), sample(1:50, 40, replace = TRUE) ), batch = c( rep(1000, 40), rep(3000, 40) ) ) %>% dplyr::mutate_all(as.character) sigmajs() %>% sg_force_start() %>% sg_read_nodes(nodes, id, label, color, size, delay = batch) %>% sg_read_edges(edges, id, source, target, delay = batch) %>% sg_force_stop(4000) %>% sg_read_exec() %>% sg_button("read_exec", "Add nodes & edges")
Add images to nodes with the Custom Shapes plugin.
sg_add_images(sg, data, url, ...)
sg_add_images(sg, data, url, ...)
sg |
An object of class |
data |
Data.frame containing columns. |
url |
URL of image. |
... |
Any other column. |
## Not run: demo("custom-shapes", package = "sigmajs") ## End(Not run)
## Not run: demo("custom-shapes", package = "sigmajs") ## End(Not run)
Proxies to dynamically add a node or an edge to an already existing graph.
sg_add_node_p(proxy, data, ..., refresh = TRUE) sg_add_edge_p(proxy, data, ..., refresh = TRUE)
sg_add_node_p(proxy, data, ..., refresh = TRUE) sg_add_edge_p(proxy, data, ..., refresh = TRUE)
proxy |
An object of class |
data |
A |
... |
any column. |
refresh |
Whether to refresh the graph after node is dropped, required to take effect, if you are running force the algorithm is killed. |
The proxy
object.
Have the parameters from your initial graph match that of the node you add, i.e.: if you pass size
in your initial chart,
make sure you also have it in your proxy.
## Not run: demo("add-node", package = "sigmajs") demo("add-edge", package = "sigmajs") demo("add-node-edge", package = "sigmajs") ## End(Not run)
## Not run: demo("add-node", package = "sigmajs") demo("add-edge", package = "sigmajs") demo("add-node-edge", package = "sigmajs") ## End(Not run)
Add nodes or edges.
sg_add_nodes(sg, data, delay, ..., cumsum = TRUE) sg_add_edges(sg, data, delay, ..., cumsum = TRUE, refresh = FALSE)
sg_add_nodes(sg, data, delay, ..., cumsum = TRUE) sg_add_edges(sg, data, delay, ..., cumsum = TRUE, refresh = FALSE)
sg |
An object of class |
data |
Data.frame (or list) of nodes or edges. |
delay |
Column name containing delay in milliseconds. |
... |
Any column name, see details. |
cumsum |
Whether to compute the cumulative sum of the delay. |
refresh |
Whether to refresh the graph after node is dropped, required to take effect, if you are running force the algorithm is killed and restarted at every iteration. |
The delay helps for build dynamic visualisations where nodes and edges do not appear all at the same time.
How the delay works depends on the cumsum
parameter. if TRUE
the function computes the cumulative sum
of the delay to effectively add each row one after the other: delay is thus applied at each row (number of seconds to wait
before the row is added *since the previous row*). If FALSE
this is the number of milliseconds to wait before the node or
edge is added to the visualisation; delay
is used as passed to the function.
A modified version of the sg
object.
# initial nodes nodes <- sg_make_nodes() # additional nodes nodes2 <- sg_make_nodes() nodes2$id <- as.character(seq(11, 20)) # add delay nodes2$delay <- runif(nrow(nodes2), 500, 1000) sigmajs() %>% sg_nodes(nodes, id, label, size, color) %>% sg_add_nodes(nodes2, delay, id, label, size, color) edges <- sg_make_edges(nodes, 25) edges$delay <- runif(nrow(edges), 100, 2000) sigmajs() %>% sg_force_start() %>% sg_nodes(nodes, id, label, size, color) %>% sg_add_edges(edges, delay, id, source, target, cumsum = FALSE) %>% sg_force_stop(2300) # stop after all edges added
# initial nodes nodes <- sg_make_nodes() # additional nodes nodes2 <- sg_make_nodes() nodes2$id <- as.character(seq(11, 20)) # add delay nodes2$delay <- runif(nrow(nodes2), 500, 1000) sigmajs() %>% sg_nodes(nodes, id, label, size, color) %>% sg_add_nodes(nodes2, delay, id, label, size, color) edges <- sg_make_edges(nodes, 25) edges$delay <- runif(nrow(edges), 100, 2000) sigmajs() %>% sg_force_start() %>% sg_nodes(nodes, id, label, size, color) %>% sg_add_edges(edges, delay, id, source, target, cumsum = FALSE) %>% sg_force_stop(2300) # stop after all edges added
Proxies to dynamically add multiple nodes or edges to an already existing graph with a *delay* between each addition.
sg_add_nodes_delay_p(proxy, data, delay, ..., refresh = TRUE, cumsum = TRUE) sg_add_edges_delay_p(proxy, data, delay, ..., refresh = TRUE, cumsum = TRUE)
sg_add_nodes_delay_p(proxy, data, delay, ..., refresh = TRUE, cumsum = TRUE) sg_add_edges_delay_p(proxy, data, delay, ..., refresh = TRUE, cumsum = TRUE)
proxy |
An object of class |
data |
A |
delay |
Column name containing delay in milliseconds. |
... |
any column. |
refresh |
Whether to refresh the graph after node is dropped, required to take effect, if you are running force the algorithm is killed and restarted at every iteration. |
cumsum |
Whether to compute the cumulative sum of the delay. |
The delay helps for build dynamic visualisations where nodes and edges do not appear all at the same time.
How the delay works depends on the cumsum
parameter. if TRUE
the function computes the cumulative sum
of the delay to effectively add each row one after the other: delay is thus applied at each row (number of seconds to wait
before the row is added *since the previous row*). If FALSE
this is the number of milliseconds to wait before the node or
edge is added to the visualisation; delay
is used as passed to the function.
The proxy
object.
Have the parameters from your initial graph match that of the node you add, i.e.: if you pass size
in your initial chart,
make sure you also have it in your proxy.
Proxies to dynamically add *multiple* nodes or edges to an already existing graph.
sg_add_nodes_p(proxy, data, ..., refresh = TRUE, rate = "once") sg_add_edges_p(proxy, data, ..., refresh = TRUE, rate = "once")
sg_add_nodes_p(proxy, data, ..., refresh = TRUE, rate = "once") sg_add_edges_p(proxy, data, ..., refresh = TRUE, rate = "once")
proxy |
An object of class |
data |
A |
... |
any column. |
refresh |
Whether to refresh the graph after node is dropped, required to take effect, if you are running force the algorithm is killed and restarted at every iteration.. |
rate |
Refresh rate, either |
The proxy
object.
Have the parameters from your initial graph match that of the node you add, i.e.: if you pass size
in your initial chart,
make sure you also have it in your proxy.
## Not run: demo("add-nodes", package = "sigmajs") demo("add-edges", package = "sigmajs") ## End(Not run)
## Not run: demo("add-nodes", package = "sigmajs") demo("add-edges", package = "sigmajs") ## End(Not run)
Animate graph components.
sg_animate(sg, mapping, options = list(easing = "cubicInOut"), delay = 5000)
sg_animate(sg, mapping, options = list(easing = "cubicInOut"), delay = 5000)
sg |
An object of class |
mapping |
Variables to map animation to. |
options |
Animations options. |
delay |
Delay in milliseconds before animation is triggered. |
You can animate, x
, y
, size
and color
.
An object of class htmlwidget
which renders the visualisation on print.
# generate graph nodes <- sg_make_nodes(20) edges <- sg_make_edges(nodes, 30) # add transition n <- nrow(nodes) nodes$to_x <- runif(n, 5, 10) nodes$to_y <- runif(n, 5, 10) nodes$to_size <- runif(n, 5, 10) sigmajs() %>% sg_nodes(nodes, id, label, size, color, to_x, to_y, to_size) %>% sg_edges(edges, id, source, target) %>% sg_animate(mapping = list(x = "to_x", y = "to_y", size = "to_size"))
# generate graph nodes <- sg_make_nodes(20) edges <- sg_make_edges(nodes, 30) # add transition n <- nrow(nodes) nodes$to_x <- runif(n, 5, 10) nodes$to_y <- runif(n, 5, 10) nodes$to_size <- runif(n, 5, 10) sigmajs() %>% sg_nodes(nodes, id, label, size, color, to_x, to_y, to_size) %>% sg_edges(edges, id, source, target) %>% sg_animate(mapping = list(x = "to_x", y = "to_y", size = "to_size"))
Proxy to dynamically animate an already existing graph.
sg_animate_p( proxy, mapping, options = list(easing = "cubicInOut"), delay = 5000 )
sg_animate_p( proxy, mapping, options = list(easing = "cubicInOut"), delay = 5000 )
proxy |
An object of class |
mapping |
Variables to map animation to. |
options |
Animations options. |
delay |
Delay in milliseconds before animation is triggered. |
You can animate, x
, y
, size
and color
.
The proxy
object.
You have to make sure that all the columns you want to animate to
(e.g. to_x
, to_size
) are also provided as arguments when you
create the graph with sigmajs() %>% sg_nodes()
.
## Not run: # generate graph nodes <- sg_make_nodes(20) edges <- sg_make_edges(nodes) # add transition n <- nrow(nodes) nodes$to_x <- runif(n, 5, 10) nodes$to_y <- runif(n, 5, 10) nodes$to_size <- runif(n, 5, 10) # in server function: output$my_sigmajs_id <- renderSigmajs({ sigmajs() %>% sg_nodes(nodes, id, label, size, color, to_x, to_y, to_size) %>% sg_edges(edges, id, source, target) }) observeEvent(input$button, { sigmajsProxy("my_sigmajs_id") %>% sg_animate_p(mapping = list(x = "to_x", y = "to_y", size = "to_size"), options = list(duration = 1000), delay = 0) }) ## End(Not run)
## Not run: # generate graph nodes <- sg_make_nodes(20) edges <- sg_make_edges(nodes) # add transition n <- nrow(nodes) nodes$to_x <- runif(n, 5, 10) nodes$to_y <- runif(n, 5, 10) nodes$to_size <- runif(n, 5, 10) # in server function: output$my_sigmajs_id <- renderSigmajs({ sigmajs() %>% sg_nodes(nodes, id, label, size, color, to_x, to_y, to_size) %>% sg_edges(edges, id, source, target) }) observeEvent(input$button, { sigmajsProxy("my_sigmajs_id") %>% sg_animate_p(mapping = list(x = "to_x", y = "to_y", size = "to_size"), options = list(duration = 1000), delay = 0) }) ## End(Not run)
Add buttons to your graph.
sg_button( sg, event, ..., position = "top", class = "btn btn-default", tag = htmltools::tags$button, id = NULL )
sg_button( sg, event, ..., position = "top", class = "btn btn-default", tag = htmltools::tags$button, id = NULL )
sg |
An object of class |
event |
Event the button triggers, see valid events. |
... |
Content of the button, complient with |
position |
Position of button, |
class |
Button |
tag |
A Valid |
id |
A valid CSS id. |
You can pass multiple events as a vector, see examples. You can also pass multiple buttons.
An object of class htmlwidget
which renders the visualisation on print.
force_start
force_stop
noverlap
drag_nodes
relative_size
add_nodes
add_edges
drop_nodes
drop_edges
animate
export_svg
export_img
progress
read_exec
The default class (btn btn-default
) works with Bootstrap 3 (the default framework for Shiny and R markdown).
nodes <- sg_make_nodes() edges <- sg_make_edges(nodes) # Button starts the layout and stops it after 3 seconds sigmajs() %>% sg_nodes(nodes, id, size) %>% sg_edges(edges, id, source, target) %>% sg_force_start() %>% sg_force_stop(3000) %>% sg_button(c("force_start", "force_stop"), "start layout") # additional nodes nodes2 <- sg_make_nodes() nodes2$id <- as.character(seq(11, 20)) # add delay nodes2$delay <- runif(nrow(nodes2), 500, 1000) sigmajs() %>% sg_nodes(nodes, id, label, size, color) %>% sg_add_nodes(nodes2, delay, id, label, size, color) %>% sg_force_start() %>% sg_force_stop(3000) %>% sg_button(c("force_start", "force_stop"), "start layout") %>% sg_button("add_nodes", "add nodes")
nodes <- sg_make_nodes() edges <- sg_make_edges(nodes) # Button starts the layout and stops it after 3 seconds sigmajs() %>% sg_nodes(nodes, id, size) %>% sg_edges(edges, id, source, target) %>% sg_force_start() %>% sg_force_stop(3000) %>% sg_button(c("force_start", "force_stop"), "start layout") # additional nodes nodes2 <- sg_make_nodes() nodes2$id <- as.character(seq(11, 20)) # add delay nodes2$delay <- runif(nrow(nodes2), 500, 1000) sigmajs() %>% sg_nodes(nodes, id, label, size, color) %>% sg_add_nodes(nodes2, delay, id, label, size, color) %>% sg_force_start() %>% sg_force_stop(3000) %>% sg_button(c("force_start", "force_stop"), "start layout") %>% sg_button("add_nodes", "add nodes")
Change nodes and edges attributes on the fly
sg_change_nodes_p( proxy, data, value, attribute, rate = c("once", "iteration"), refresh = TRUE, delay = NULL ) sg_change_edges_p( proxy, data, value, attribute, rate = c("once", "iteration"), refresh = TRUE, delay = NULL )
sg_change_nodes_p( proxy, data, value, attribute, rate = c("once", "iteration"), refresh = TRUE, delay = NULL ) sg_change_edges_p( proxy, data, value, attribute, rate = c("once", "iteration"), refresh = TRUE, delay = NULL )
proxy |
An object of class |
data |
|
value |
Column containing value. |
attribute |
Name of attribute to change. |
rate |
Rate at chich to refresh takes |
refresh |
Whether to refresh the graph after the change is made. |
delay |
Optional delay in milliseconds before change is applied. If |
library(shiny) nodes <- sg_make_nodes() nodes$new_color <- "red" edges <- sg_make_edges(nodes) ui <- fluidPage( actionButton("start", "Change color"), sigmajsOutput("sg") ) server <- function(input, output){ output$sg <- renderSigmajs({ sigmajs() %>% sg_nodes(nodes, id, size, color) %>% sg_edges(edges, id, source, target) }) observeEvent(input$start, { sigmajsProxy("sg") %>% # use sigmajsProxy! sg_change_nodes_p(nodes, new_color, "color") }) } if (interactive()) shinyApp(ui, server) # run
library(shiny) nodes <- sg_make_nodes() nodes$new_color <- "red" edges <- sg_make_edges(nodes) ui <- fluidPage( actionButton("start", "Change color"), sigmajsOutput("sg") ) server <- function(input, output){ output$sg <- renderSigmajs({ sigmajs() %>% sg_nodes(nodes, id, size, color) %>% sg_edges(edges, id, source, target) }) observeEvent(input$start, { sigmajsProxy("sg") %>% # use sigmajsProxy! sg_change_nodes_p(nodes, new_color, "color") }) } if (interactive()) shinyApp(ui, server) # run
Clear all nodes and edges from the graph or kills the graph.
Kill the graph to ensure new data is redrawn, useful in Shiny
when graph is not updated by sigmajsProxy
.
sg_clear_p(proxy, refresh = TRUE) sg_kill_p(proxy, refresh = TRUE) sg_kill(sg) sg_clear(sg)
sg_clear_p(proxy, refresh = TRUE) sg_kill_p(proxy, refresh = TRUE) sg_kill(sg) sg_clear(sg)
proxy |
An object of class |
refresh |
Whether to refresh the graph after node is dropped, required to take effect, if you are running force the algorithm is killed and restarted. |
sg |
An object of class |
The proxy
object.
A modified version of the sg
object.
Color nodes by cluster.
sg_cluster( sg, colors = c("#B1E2A3", "#98D3A5", "#328983", "#1C5C70", "#24C96B"), directed = TRUE, algo = igraph::cluster_walktrap, quiet = !interactive(), save_igraph = TRUE, ... ) sg_get_cluster( nodes, edges, colors = c("#B1E2A3", "#98D3A5", "#328983", "#1C5C70", "#24C96B"), directed = TRUE, algo = igraph::cluster_walktrap, quiet = !interactive(), save_igraph = TRUE, ... )
sg_cluster( sg, colors = c("#B1E2A3", "#98D3A5", "#328983", "#1C5C70", "#24C96B"), directed = TRUE, algo = igraph::cluster_walktrap, quiet = !interactive(), save_igraph = TRUE, ... ) sg_get_cluster( nodes, edges, colors = c("#B1E2A3", "#98D3A5", "#328983", "#1C5C70", "#24C96B"), directed = TRUE, algo = igraph::cluster_walktrap, quiet = !interactive(), save_igraph = TRUE, ... )
sg |
An object of class |
colors |
Palette to color the nodes. |
directed |
Whether or not to create a directed graph, passed to |
algo |
An |
quiet |
Set to |
save_igraph |
Whether to save the |
... |
Any parameter to pass to |
nodes , edges
|
Nodes and edges as prepared for sigmajs. |
The package uses igraph
internally for a lot of computations the save_igraph
allows saving the object to speed up subsequent computations.
sg_get_cluster
returns nodes with color
variable while
sg_cluster
returns an object of class htmlwidget
which renders
the visualisation on print.
sg_cluster
Color nodes by cluster.
sg_get_cluster
helper to get graph's nodes color by cluster.
nodes <- sg_make_nodes() edges <- sg_make_edges(nodes, 15) sigmajs() %>% sg_nodes(nodes, id, size) %>% sg_edges(edges, id, source, target) %>% sg_layout() %>% sg_cluster() clustered <- sg_get_cluster(nodes, edges)
nodes <- sg_make_nodes() edges <- sg_make_edges(nodes, 15) sigmajs() %>% sg_nodes(nodes, id, size) %>% sg_edges(edges, id, source, target) %>% sg_layout() %>% sg_cluster() clustered <- sg_get_cluster(nodes, edges)
Indicate a graph uses custom shapes
sg_custom_shapes(sg)
sg_custom_shapes(sg)
sg |
An object of class |
Allow user to drag and drop nodes.
sg_drag_nodes(sg) sg_drag_nodes_start_p(proxy) sg_drag_nodes_kill_p(proxy)
sg_drag_nodes(sg) sg_drag_nodes_start_p(proxy) sg_drag_nodes_kill_p(proxy)
sg |
An object of class |
proxy |
An object of class |
sg_drag_nodes
An object of class htmlwidget
which renders the visualisation on print.
While sg_drag_nodes_start_p
and sg_drag_nodes_kill_p
# generate graph nodes <- sg_make_nodes(20) edges <- sg_make_edges(nodes, 35) sigmajs() %>% sg_nodes(nodes, id, label, size) %>% sg_edges(edges, id, source, target) %>% sg_drag_nodes() ## Not run: # proxies demo("drag-nodes", package = "sigmajs") ## End(Not run)
# generate graph nodes <- sg_make_nodes(20) edges <- sg_make_edges(nodes, 35) sigmajs() %>% sg_nodes(nodes, id, label, size) %>% sg_edges(edges, id, source, target) %>% sg_drag_nodes() ## Not run: # proxies demo("drag-nodes", package = "sigmajs") ## End(Not run)
Proxies to dynamically remove a node or an edge to an already existing graph.
sg_drop_node_p(proxy, id, refresh = TRUE) sg_drop_edge_p(proxy, id, refresh = TRUE)
sg_drop_node_p(proxy, id, refresh = TRUE) sg_drop_edge_p(proxy, id, refresh = TRUE)
proxy |
An object of class |
id |
Id of edge or node to delete. |
refresh |
Whether to refresh the graph after node is dropped, required to take effect, if you are running force the algorithm is killed and restarted. |
The proxy
object.
Drop nodes or edges.
sg_drop_nodes(sg, data, ids, delay, cumsum = TRUE) sg_drop_edges(sg, data, ids, delay, cumsum = TRUE, refresh = FALSE)
sg_drop_nodes(sg, data, ids, delay, cumsum = TRUE) sg_drop_edges(sg, data, ids, delay, cumsum = TRUE, refresh = FALSE)
sg |
An object of class |
data |
Data.frame (or list) of nodes or edges. |
ids |
Ids of elements to drop. |
delay |
Column name containing delay in milliseconds. |
cumsum |
Whether to compute the cumulative sum of the delay. |
refresh |
Whether to refresh the graph after node is dropped, required to take effect, if you are running force the algorithm is killed and restarted at every iteration. |
The delay helps for build dynamic visualisations where nodes and edges do not disappear all at the same time.
How the delay works depends on the cumsum
parameter. if TRUE
the function computes the cumulative sum
of the delay to effectively drop each row one after the other: delay is thus applied at each row (number of seconds to wait
before the row is dropped *since the previous row*). If FALSE
this is the number of milliseconds to wait before the node or
edge is dropped to the visualisation; delay
is used as passed to the function.
A modified version of the sg
object.
nodes <- sg_make_nodes(75) # nodes to drop nodes2 <- nodes[sample(nrow(nodes), 50), ] nodes2$delay <- runif(nrow(nodes2), 1000, 3000) sigmajs() %>% sg_nodes(nodes, id, size, color) %>% sg_drop_nodes(nodes2, id, delay, cumsum = FALSE)
nodes <- sg_make_nodes(75) # nodes to drop nodes2 <- nodes[sample(nrow(nodes), 50), ] nodes2$delay <- runif(nrow(nodes2), 1000, 3000) sigmajs() %>% sg_nodes(nodes, id, size, color) %>% sg_drop_nodes(nodes2, id, delay, cumsum = FALSE)
Proxies to dynamically drop multiple nodes or edges to an already existing graph with a *delay* between each removal.
sg_drop_nodes_delay_p(proxy, data, ids, delay, refresh = TRUE, cumsum = TRUE) sg_drop_edges_delay_p(proxy, data, ids, delay, refresh = TRUE, cumsum = TRUE)
sg_drop_nodes_delay_p(proxy, data, ids, delay, refresh = TRUE, cumsum = TRUE) sg_drop_edges_delay_p(proxy, data, ids, delay, refresh = TRUE, cumsum = TRUE)
proxy |
An object of class |
data |
A |
ids |
Ids of elements to drop. |
delay |
Column name containing delay in milliseconds. |
refresh |
Whether to refresh the graph after node is dropped, required to take effect, if you are running force the algorithm is killed and restarted at every iteration. |
cumsum |
Whether to compute the cumulative sum of the delay. |
The delay helps for build dynamic visualisations where nodes and edges do not disappear all at the same time.
How the delay works depends on the cumsum
parameter. if TRUE
the function computes the cumulative sum
of the delay to effectively drop each row one after the other: delay is thus applied at each row (number of seconds to wait
before the row is dropped *since the previous row*). If FALSE
this is the number of milliseconds to wait before the node or
edge is added to the visualisation; delay
is used as passed to the function.
The proxy
object.
Have the parameters from your initial graph match that of the node you add, i.e.: if you pass size
in your initial chart,
make sure you also have it in your proxy.
Proxies to dynamically drop *multiple* nodes or edges from an already existing graph.
sg_drop_nodes_p(proxy, data, ids, refresh = TRUE, rate = "once") sg_drop_edges_p(proxy, data, ids, refresh = TRUE, rate = "once")
sg_drop_nodes_p(proxy, data, ids, refresh = TRUE, rate = "once") sg_drop_edges_p(proxy, data, ids, refresh = TRUE, rate = "once")
proxy |
An object of class |
data |
A |
ids |
Column containing ids to drop from the graph. |
refresh |
Whether to refresh the graph after node is dropped, required to take effect. |
rate |
Refresh rate, either |
The proxy
object.
Have the parameters from your initial graph match that of the node you add, i.e.: if you pass size
in your initial chart,
make sure you also have it in your proxy.
React to user-interaction events on the server-side in Shiny.
sg_events(sg, events)
sg_events(sg, events)
sg |
An object of class |
events |
A vector or list of valid events (see section below). |
The parameter events
is either a simple vector with the valid names of
events (see below), e.g. c("clickNode", "overNode")
.
An alternative possibility for events
is to pass a list of named lists,
where each named list has an entry "event" with the valid event name and
optionally an entry "priority" specifying the priority of the event, e.g.
list(list(event = "clickNode"), list(event = "overNode", priority = "event"))
.
A priority of mode "event" means that the event is dispatched every time, not only when its returned value changes. Shiny's default priority "immediate" (also used when no priority is specified) would only dispatch when e.g. the clicked or hovered node is different from before. See https://shiny.rstudio.com/articles/communicating-with-js.html for more information.
Events:
Valid event names to pass to events
.
clickNode
clickNodes
clickEdge
clickEdges
clickStage
doubleClickStage
rightClickStage
doubleClickNode
doubleClickNodes
doubleClickEdge
doubleClickEdges
rightClickNode
rightClickNodes
rightClickEdge
rightClickEdges
overNode
overNodes
overEdge
overEdges
outNode
outNodes
outEdge
outEdges
The corresponding Shiny events to observe have the same name, only written in
lowercase, words separated with underscores, and prefixed with the
outputId
of the sigmajsOutput()
. For example, when outputId
is "graph": the clickNode
event in Shiny becomes input$graph_click_node
,
the overNode
event in Shiny becomes input$graph_over_node
, and
so on.
An object of class htmlwidget
which renders the visualisation on print.
official sigmajs documentation, Shiny article about communicating with JavaScript.
library(shiny) nodes <- sg_make_nodes() edges <- sg_make_edges(nodes) ui <- fluidPage( sigmajsOutput("graph"), p("Click on a node"), verbatimTextOutput("clicked") ) server <- function(input, output){ output$graph <- renderSigmajs({ sigmajs() %>% sg_nodes(nodes, id, size, color) %>% sg_edges(edges, id, source, target) %>% sg_events("clickNode") }) # capture node clicked (only fires when a new node is clicked) output$clicked <- renderPrint({ c(list(clickTime = Sys.time()), input$graph_click_node) }) } ## Not run: shinyApp(ui, server) server2 <- function(input, output){ output$graph <- renderSigmajs({ sigmajs() %>% sg_nodes(nodes, id, size, color) %>% sg_edges(edges, id, source, target) %>% sg_events(list(list(event = "clickNode", priority = "event"))) }) # capture node clicked (every time, also when clicking the same node again) output$clicked <- renderPrint({ c(list(clickTime = Sys.time()), input$graph_click_node) }) } ## Not run: shinyApp(ui, server2)
library(shiny) nodes <- sg_make_nodes() edges <- sg_make_edges(nodes) ui <- fluidPage( sigmajsOutput("graph"), p("Click on a node"), verbatimTextOutput("clicked") ) server <- function(input, output){ output$graph <- renderSigmajs({ sigmajs() %>% sg_nodes(nodes, id, size, color) %>% sg_edges(edges, id, source, target) %>% sg_events("clickNode") }) # capture node clicked (only fires when a new node is clicked) output$clicked <- renderPrint({ c(list(clickTime = Sys.time()), input$graph_click_node) }) } ## Not run: shinyApp(ui, server) server2 <- function(input, output){ output$graph <- renderSigmajs({ sigmajs() %>% sg_nodes(nodes, id, size, color) %>% sg_edges(edges, id, source, target) %>% sg_events(list(list(event = "clickNode", priority = "event"))) }) # capture node clicked (every time, also when clicking the same node again) output$clicked <- renderPrint({ c(list(clickTime = Sys.time()), input$graph_click_node) }) } ## Not run: shinyApp(ui, server2)
Export graph to SVG.
sg_export_svg( sg, download = TRUE, file = "graph.svg", size = 1000, width = 1000, height = 1000, labels = FALSE, data = FALSE ) sg_export_img( sg, download = TRUE, file = "graph.png", background = "white", format = "png", labels = FALSE ) sg_export_img_p( proxy, download = TRUE, file = "graph.png", background = "white", format = "png", labels = FALSE ) sg_export_svg_p( proxy, download = TRUE, file = "graph.svg", size = 1000, width = 1000, height = 1000, labels = FALSE, data = FALSE )
sg_export_svg( sg, download = TRUE, file = "graph.svg", size = 1000, width = 1000, height = 1000, labels = FALSE, data = FALSE ) sg_export_img( sg, download = TRUE, file = "graph.png", background = "white", format = "png", labels = FALSE ) sg_export_img_p( proxy, download = TRUE, file = "graph.png", background = "white", format = "png", labels = FALSE ) sg_export_svg_p( proxy, download = TRUE, file = "graph.svg", size = 1000, width = 1000, height = 1000, labels = FALSE, data = FALSE )
sg |
An object of class |
download |
set to |
file |
Name of file. |
size |
Size of the SVG in pixels. |
width , height
|
Width and height of the SVG in pixels. |
labels |
Whether the labels should be included in the svg file. |
data |
Whether additional data (node ids for instance) should be included in the svg file. |
background |
Background color of image. |
format |
Format of image, takes |
proxy |
An object of class |
An object of class htmlwidget
which renders the visualisation on print.
Functions ending in _p
return the proxy
.
nodes <- sg_make_nodes() edges <- sg_make_edges(nodes, 17) sigmajs() %>% sg_nodes(nodes, id, size) %>% sg_edges(edges, id, source, target) %>% sg_export_svg() %>% sg_button("export_svg", "download")
nodes <- sg_make_nodes() edges <- sg_make_edges(nodes, 17) sigmajs() %>% sg_nodes(nodes, id, size) %>% sg_edges(edges, id, source, target) %>% sg_export_svg() %>% sg_button("export_svg", "download")
Filter nodes and/or edges.
sg_filter_gt_p( proxy, input, var, target = c("nodes", "edges", "both"), name = NULL ) sg_filter_lt_p( proxy, input, var, target = c("nodes", "edges", "both"), name = NULL ) sg_filter_eq_p( proxy, input, var, target = c("nodes", "edges", "both"), name = NULL ) sg_filter_not_eq_p( proxy, input, var, target = c("nodes", "edges", "both"), name = NULL ) sg_filter_undo_p(proxy, name) sg_filter_neighbours_p(proxy, node, name = NULL)
sg_filter_gt_p( proxy, input, var, target = c("nodes", "edges", "both"), name = NULL ) sg_filter_lt_p( proxy, input, var, target = c("nodes", "edges", "both"), name = NULL ) sg_filter_eq_p( proxy, input, var, target = c("nodes", "edges", "both"), name = NULL ) sg_filter_not_eq_p( proxy, input, var, target = c("nodes", "edges", "both"), name = NULL ) sg_filter_undo_p(proxy, name) sg_filter_neighbours_p(proxy, node, name = NULL)
proxy |
An object of class |
input |
A Shiny input. |
var |
Variable to filter. |
target |
Target of filter, |
name |
Name of the filter, useful to undo the filter later on with |
node |
Node id to filter neighbours. |
The proxy
object.
sg_filter_gt_p
Filter greater than var
.
sg_filter_lt_p
Filter less than var
.
sg_filter_eq_p
Filter equal to var
.
sg_filter_not_eq_p
Filter not equal to var
.
sg_filter_undo_p
Undo filters, accepts vector of name
s.
Create a sigmajs graph from a GEXF file.
sg_from_gexf(sg, file, sd = NULL)
sg_from_gexf(sg, file, sd = NULL)
sg |
An object of class |
file |
Path to GEXF file. |
sd |
A SharedData of nodes. |
A modified version of the sg
object.
## Not run: gexf <- "https://gephi.org/gexf/data/yeast.gexf" sigmajs() %>% sg_from_gexf(gexf) ## End(Not run)
## Not run: gexf <- "https://gephi.org/gexf/data/yeast.gexf" sigmajs() %>% sg_from_gexf(gexf) ## End(Not run)
Create a sigmajs
from an igraph
object.
sg_from_igraph(sg, igraph, layout = NULL, sd = NULL)
sg_from_igraph(sg, igraph, layout = NULL, sd = NULL)
sg |
An object of class |
igraph |
An object of class |
layout |
A matrix of coordinates. |
sd |
A SharedData of nodes. |
A modified version of the sg
object.
## Not run: data("lesmis_igraph") layout <- igraph::layout_with_fr(lesmis_igraph) sigmajs() %>% sg_from_igraph(lesmis_igraph, layout) %>% sg_settings(defaultNodeColor = "#000") ## End(Not run)
## Not run: data("lesmis_igraph") layout <- igraph::layout_with_fr(lesmis_igraph) sigmajs() %>% sg_from_igraph(lesmis_igraph, layout) %>% sg_settings(defaultNodeColor = "#000") ## End(Not run)
Retrieve nodes and edges from the widget.
sg_get_nodes_p(proxy) sg_get_edges_p(proxy)
sg_get_nodes_p(proxy) sg_get_edges_p(proxy)
proxy |
An object of class |
The proxy
object.
library(shiny) nodes <- sg_make_nodes() edges <- sg_make_edges(nodes) ui <- fluidPage( actionButton("start", "Trigger layout"), # add the button sigmajsOutput("sg"), verbatimTextOutput("txt") ) server <- function(input, output){ output$sg <- renderSigmajs({ sigmajs() %>% sg_nodes(nodes, id, size, color) %>% sg_edges(edges, id, source, target) }) observeEvent(input$start, { sigmajsProxy("sg") %>% # use sigmajsProxy! sg_get_nodes_p() }) output$txt <- renderPrint({ input$sg_nodes }) } if (interactive()) shinyApp(ui, server) # run
library(shiny) nodes <- sg_make_nodes() edges <- sg_make_edges(nodes) ui <- fluidPage( actionButton("start", "Trigger layout"), # add the button sigmajsOutput("sg"), verbatimTextOutput("txt") ) server <- function(input, output){ output$sg <- renderSigmajs({ sigmajs() %>% sg_nodes(nodes, id, size, color) %>% sg_edges(edges, id, source, target) }) observeEvent(input$start, { sigmajsProxy("sg") %>% # use sigmajsProxy! sg_get_nodes_p() }) output$txt <- renderPrint({ input$sg_nodes }) } if (interactive()) shinyApp(ui, server) # run
Layout your graph.
sg_layout( sg, directed = TRUE, layout = igraph::layout_nicely, save_igraph = TRUE, ... ) sg_get_layout( nodes, edges, directed = TRUE, layout = igraph::layout_nicely, save_igraph = TRUE, ... )
sg_layout( sg, directed = TRUE, layout = igraph::layout_nicely, save_igraph = TRUE, ... ) sg_get_layout( nodes, edges, directed = TRUE, layout = igraph::layout_nicely, save_igraph = TRUE, ... )
sg |
An object of class |
directed |
Whether or not to create a directed graph, passed to |
layout |
An |
save_igraph |
Whether to save the |
... |
Any other parameter to pass to |
nodes , edges
|
Nodes and edges as prepared for sigmajs. |
The package uses igraph
internally for a lot of computations the save_igraph
allows saving the object to speed up subsequent computations.
sg_get_layout
returns nodes with x
and y
coordinates.
sg_layout
layout your graph.
sg_get_layout
helper to get graph's x
and y
positions.
nodes <- sg_make_nodes(250) # 250 nodes edges <- sg_make_edges(nodes, n = 500) sigmajs() %>% sg_nodes(nodes, id, size, color) %>% sg_edges(edges, id, source, target) %>% sg_layout() nodes_coords <- sg_get_layout(nodes, edges)
nodes <- sg_make_nodes(250) # 250 nodes edges <- sg_make_edges(nodes, n = 500) sigmajs() %>% sg_nodes(nodes, id, size, color) %>% sg_edges(edges, id, source, target) %>% sg_layout() nodes_coords <- sg_get_layout(nodes, edges)
Generate nodes and edges.
sg_make_nodes( n = 10, colors = c("#B1E2A3", "#98D3A5", "#328983", "#1C5C70", "#24C96B") ) sg_make_edges(nodes, n = NULL) sg_make_nodes_edges(n, ...)
sg_make_nodes( n = 10, colors = c("#B1E2A3", "#98D3A5", "#328983", "#1C5C70", "#24C96B") ) sg_make_edges(nodes, n = NULL) sg_make_nodes_edges(n, ...)
n |
Number of nodes. |
colors |
Color palette to use. |
nodes |
Nodes, as generated by |
... |
Any other argument to pass to sample_pa. |
tibble
of nodes or edges or a list
of the latter.
sg_make_nodes
generate data.frame nodes.
sg_make_edges
generate data.frame edges.
sg_make_nodes_edges
generate list of nodes and edges.
nodes <- sg_make_nodes() edges <- sg_make_edges(nodes) sigmajs() %>% sg_nodes(nodes, id, label, size, color) %>% sg_edges(edges, id, source, target) %>% sg_settings(defaultNodeColor = "#0011ff")
nodes <- sg_make_nodes() edges <- sg_make_edges(nodes) sigmajs() %>% sg_nodes(nodes, id, label, size, color) %>% sg_edges(edges, id, source, target) %>% sg_settings(defaultNodeColor = "#0011ff")
Highlight node neighbours on click.
sg_neighbours( sg, nodes = "#eee", edges = "#eee", on = c("clickNode", "overNode", "clickNode|overNode") ) sg_neighbors( sg, nodes = "#eee", edges = "#eee", on = c("clickNode", "overNode", "clickNode|overNode") ) sg_neighbours_p( proxy, nodes = "#eee", edges = "#eee", on = c("clickNode", "overNode", "clickNode|overNode") ) sg_neighbors_p( proxy, nodes = "#eee", edges = "#eee", on = c("clickNode", "overNode", "clickNode|overNode") )
sg_neighbours( sg, nodes = "#eee", edges = "#eee", on = c("clickNode", "overNode", "clickNode|overNode") ) sg_neighbors( sg, nodes = "#eee", edges = "#eee", on = c("clickNode", "overNode", "clickNode|overNode") ) sg_neighbours_p( proxy, nodes = "#eee", edges = "#eee", on = c("clickNode", "overNode", "clickNode|overNode") ) sg_neighbors_p( proxy, nodes = "#eee", edges = "#eee", on = c("clickNode", "overNode", "clickNode|overNode") )
sg |
An object of class |
nodes , edges
|
Color of nodes and edges |
on |
The sigmajs event on which to trigger the neighbours highlighting. 'clickNode' (default) means when a node is clicked on. 'overNode' means when mouse is hovering on a node. 'clickNode|overNode' means a combination of the two modes at the same time. |
proxy |
An object of class |
A modified version of the sg
object.
nodes <- sg_make_nodes() edges <- sg_make_edges(nodes, 20) sigmajs() %>% sg_nodes(nodes, id, size, color) %>% sg_edges(edges, id, source, target) %>% sg_layout() %>% sg_neighbours()
nodes <- sg_make_nodes() edges <- sg_make_edges(nodes, 20) sigmajs() %>% sg_nodes(nodes, id, size, color) %>% sg_edges(edges, id, source, target) %>% sg_layout() %>% sg_neighbours()
Add nodes and edges to a sigmajs
graph.
sg_nodes(sg, data, ...) sg_edges(sg, data, ...) sg_edges2(sg, data) sg_nodes2(sg, data)
sg_nodes(sg, data, ...) sg_edges(sg, data, ...) sg_edges2(sg, data) sg_nodes2(sg, data)
sg |
An object of class |
data |
Data.frame (or list) of nodes or edges. |
... |
Any column name, see details. |
nodes:
Must pass id
(unique), size
and color
. If color
is omitted, then 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 id
s. If an edges goes from or to an id
that is not in node id
.
A modified version of the sg
object.
Functions ending in 2
take a list like the original sigma.js JSON.
Other functions take the arguments described above.
node
also takes a SharedData.
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)
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)
This plugin runs an algorithm which distributes nodes in the network, ensuring that they do not overlap and providing a margin where specified.
sg_noverlap(sg, ...) sg_noverlap_p(proxy, nodeMargin = 5, ...)
sg_noverlap(sg, ...) sg_noverlap_p(proxy, nodeMargin = 5, ...)
sg |
An object of class |
... |
any option to pass to the plugin, see official documentation. |
proxy |
An object of class |
nodeMargin |
The additional minimum space to apply around each and every node. |
The first argument either sg
or proxy
.
nodes <- sg_make_nodes(500) edges <- sg_make_edges(nodes) sigmajs() %>% sg_nodes(nodes, id, size, color) %>% sg_edges(edges, id, source, target) %>% sg_layout() %>% sg_noverlap()
nodes <- sg_make_nodes(500) edges <- sg_make_edges(nodes) sigmajs() %>% sg_nodes(nodes, id, size, color) %>% sg_edges(edges, id, source, target) %>% sg_layout() %>% sg_noverlap()
Add text to your graph.
sg_progress( sg, data, delay, text, ..., position = "top", id = NULL, tag = htmltools::span, cumsum = TRUE )
sg_progress( sg, data, delay, text, ..., position = "top", id = NULL, tag = htmltools::span, cumsum = TRUE )
sg |
An object of class |
data |
Data.frame holding |
delay |
Delay, in milliseconds at which text should appear. |
text |
Text to appear on graph. |
... |
Content of the button, complient with |
position |
Position of button, |
id |
A valid CSS id. |
tag |
A Valid |
cumsum |
Whether to compute the cumulative sum on the |
The element
is passed to Document.createElement()
and therefore takes any valid tagName
, including, but not limited to; p
, h1
, div
.
A modified version of the sg
object.
# initial nodes nodes <- sg_make_nodes() # additional nodes nodes2 <- sg_make_nodes() nodes2$id <- as.character(seq(11, 20)) # add delay nodes2$delay <- runif(nrow(nodes2), 500, 1000) nodes2$text <- seq.Date(Sys.Date(), Sys.Date() + 9, "days") sigmajs() %>% sg_nodes(nodes, id, label, size, color) %>% sg_add_nodes(nodes2, delay, id, label, size, color) %>% sg_progress(nodes2, delay, text, element = "h3") %>% sg_button(c("add_nodes", "progress"), "add")
# initial nodes nodes <- sg_make_nodes() # additional nodes nodes2 <- sg_make_nodes() nodes2$id <- as.character(seq(11, 20)) # add delay nodes2$delay <- runif(nrow(nodes2), 500, 1000) nodes2$text <- seq.Date(Sys.Date(), Sys.Date() + 9, "days") sigmajs() %>% sg_nodes(nodes, id, label, size, color) %>% sg_add_nodes(nodes2, delay, id, label, size, color) %>% sg_progress(nodes2, delay, text, element = "h3") %>% sg_button(c("add_nodes", "progress"), "add")
Refresh your instance.
sg_refresh_p(proxy)
sg_refresh_p(proxy)
proxy |
An object of class |
It is often required to refresh the instance when using proxies.
Change nodes size depending to their degree (number of relationships)
sg_relative_size(sg, initial = 1)
sg_relative_size(sg, initial = 1)
sg |
An object of class |
initial |
Initial node size. |
A modified version of the sg
object.
nodes <- sg_make_nodes(50) edges <- sg_make_edges(nodes, 100) sigmajs() %>% sg_nodes(nodes, id, label) %>% # no need to pass size sg_edges(edges, id, source, target) %>% sg_relative_size()
nodes <- sg_make_nodes(50) edges <- sg_make_edges(nodes, 100) sigmajs() %>% sg_nodes(nodes, id, label) %>% # no need to pass size sg_edges(edges, id, source, target) %>% sg_relative_size()
Graph settings.
sg_settings(sg, ...) sg_settings_p(proxy, ...)
sg_settings(sg, ...) sg_settings_p(proxy, ...)
sg |
An object of class |
... |
Any parameter, see official documentation. |
proxy |
A proxy as returned by |
nodes <- sg_make_nodes() edges <- sg_make_edges(nodes, 50) sigmajs() %>% sg_nodes(nodes, id, label, size) %>% sg_edges(edges, id, source, target) %>% sg_force() %>% sg_settings( defaultNodeColor = "#0011ff" )
nodes <- sg_make_nodes() edges <- sg_make_edges(nodes, 50) sigmajs() %>% sg_nodes(nodes, id, label, size) %>% sg_edges(edges, id, source, target) %>% sg_force() %>% sg_settings( defaultNodeColor = "#0011ff" )
Dynamically Zoom a node.
sg_zoom_p(proxy, id, ratio = 0.5, duration = 1000)
sg_zoom_p(proxy, id, ratio = 0.5, duration = 1000)
proxy |
An object of class |
id |
Node id to zoom to. |
ratio |
The zoom ratio of the graph and its items. |
duration |
Duration of animation. |
Initialise a graph.
sigmajs( type = NULL, width = "100%", kill = FALSE, height = NULL, elementId = NULL )
sigmajs( type = NULL, width = "100%", kill = FALSE, height = NULL, elementId = NULL )
type |
Renderer type, one of |
width , height
|
Dimensions of graph. |
kill |
Whether to kill the graph, set to |
elementId |
Id of elment. |
An object of class htmlwidget
which renders the visualisation on print.
Keep width
at 100%
for a responsive visualisation.
nodes <- sg_make_nodes() edges <- sg_make_edges(nodes) sigmajs("svg") %>% sg_nodes(nodes, id, label, size, color) %>% sg_edges(edges, id, source, target)
nodes <- sg_make_nodes() edges <- sg_make_edges(nodes) sigmajs("svg") %>% sg_nodes(nodes, id, label, size, color) %>% sg_edges(edges, id, source, target)
Output and render functions for using sigmajs within Shiny applications and interactive Rmd documents.
sigmajsOutput(outputId, width = "100%", height = "400px") renderSigmajs(expr, env = parent.frame(), quoted = FALSE) sigmajsProxy(id, session = shiny::getDefaultReactiveDomain())
sigmajsOutput(outputId, width = "100%", height = "400px") renderSigmajs(expr, env = parent.frame(), quoted = FALSE) sigmajsProxy(id, session = shiny::getDefaultReactiveDomain())
outputId , id
|
output variable to read from |
width , height
|
Must be a valid CSS unit (like |
expr |
An expression that generates a sigmajs |
env |
The environment in which to evaluate |
quoted |
Is |
session |
A valid shiny session. |