gs_add_nodes: Add nodes to a GraphSpace object

gs_add_nodesR Documentation

Add nodes to a GraphSpace object

Description

gs_add_nodes() and gs_add_nodes<- add one or more nodes to a GraphSpace object. The @graph, @nodes, and @fdata slots are updated consistently. Because new nodes introduce coordinates into the existing layout, the normalized state is invalidated and normalizeGraphSpace must be re-run afterwards.

gs_add_nodes(x, value) is the pipe-friendly functional form and returns the modified object. gs_add_nodes(x) <- value is the in-place replacement form and modifies x by reference in the calling environment. Both forms are equivalent.

Usage

## S4 method for signature 'GraphSpace'
gs_add_nodes(x, value, ...)

## S4 replacement method for signature 'GraphSpace'
gs_add_nodes(x) <- value

Arguments

x

A GraphSpace object.

value

A data frame with, at minimum, a name column giving the node identifier (character). The x and y columns, if not provided, are assigned random values within the range of the graph space. Any additional columns are treated as node attributes. Standard visual attributes (nodeSize, nodeColor, nodeShape, etc.) are filled from package defaults when omitted. The vertex column is reserved and is stripped automatically if present. Alternatively, a character vector of node names can be supplied; it will be converted internally to a data frame with a single name column.

...

Additional arguments (currently unused; reserved for future use).

Details

Adding nodes always invalidates the normalized layout. The @pars normalization flags are cleared, @canvas is reset, and normalizeGraphSpace must be re-run to restore a renderable state. The @edges slot is not affected. Existing node coordinates in @nodes revert to raw graph-space values if the object was previously normalized, since normalization is cleared before @nodes is rebuilt.

Standard node attributes (nodeSize, nodeColor, etc.) are kept consistent across old and new nodes: attributes present on existing nodes but absent from value are filled from package defaults for the new rows, and vice versa.

nodeLabel defaults to the node name when not supplied, consistent with the behaviour of the GraphSpace constructor.

If @fdata is non-empty, new nodes are appended as NA rows so the feature matrix remains aligned with @nodes.

Value

A GraphSpace object with the new nodes appended and the normalized state cleared.

See Also

gs_add_edges, gs_vertex_attr, gs_subset_nodes, gs_nodes

Examples

library(RGraphSpace)
library(igraph)

g <- make_star(5, mode = "out")
gs <- GraphSpace(g)

# Functional form (pipe-friendly): returns a modified copy
gs <- gs_add_nodes(gs, data.frame(name = "n6", x = 0.5, y = 0.5))

# Assignment form: modifies gs in place
gs_add_nodes(gs) <- data.frame(name = "n7", x = 0.5, y = 0.5)

# Add two nodes; x and y are assigned random values
gs_add_nodes(gs) <- c("new_node1", "new_node2")

# Add multiple nodes with visual attributes
gs <- gs_add_nodes(gs, data.frame(
  name      = c("n8", "n9"),
  x         = c(0.5, 0.8),
  y         = c(0.5, 0.2),
  nodeSize  = c(8, 5),
  nodeColor = c("steelblue", "tomato")
))


RGraphSpace documentation built on Oct. 9, 2026, 9:07 a.m.