Skip to contents

GraphSpace is the main constructor for GraphSpace objects, designed to store graph data and metadata for optimized rendering in RGraphSpace.

Usage

GraphSpace(
  g,
  layout = NULL,
  verbose = TRUE,
  mar = deprecated(),
  image = deprecated()
)

Arguments

g

An igraph object. It must include vertex coordinates assigned to x and y attributes, and vertex labels assigned to name attribute.

layout

An optional numeric matrix with two columns for x and y vertex coordinates. If provided, it overrides coordinates in g.

verbose

A logical value. If TRUE, displays detailed messages.

mar

[Deprecated] Deprecated since RGraphSpace 1.1.1; use normalizeGraphSpace instead.

image

[Deprecated] Deprecated since RGraphSpace 1.1.1; use normalizeGraphSpace instead.

Value

A GraphSpace class object.

Details

GraphSpace objects are designed to bridge the gap between network analysis (via igraph) and high-quality visualization (via ggplot2). The constructor ensures that all necessary aesthetics for geom_graphspace are pre-processed and validated.

Coordinate System and Normalization: By default, the constructor expects coordinates in the x and y vertex attributes, along with unique IDs in the name vertex attribute. If these are not provided, the constructor will generate sequential IDs and assign a layout using the layout_nicely function. These coordinates define the relative positioning of nodes. For optimal rendering, it is recommended to pass the object through normalizeGraphSpace after construction. This converts vertex positions to Normalized Parent Coordinates (NPC), ensuring the graph remains centered and scaled relative to the plotting area.

Data Structure: The resulting object stores nodes and edges in separate internal slots, preserving metadata such as nodeSize and edgeLineColor. If an igraph object is provided without specific styling attributes, GraphSpace will assign the default values defined in the geom_graphspace aesthetics. Users can also specify custom variables in the input graph to be used as aesthetics within the ggplot2 grammar.

Arrowhead Mapping: The arrowType attribute (see Arrowhead types section) allows for a mapping between symbolic aliases (such as "-->") and internal integer codes. This is useful for assigning interaction types in directed or undirected graphs (e.g., activation vs. inhibition).

Vertex attributes

The following attributes in g are evaluated by the constructor:

nodeSizeNumeric [0, 100], representing % of the plotting space.
nodeShapeInteger code [0-25]; see points.
nodeColorA valid color name or hexadecimal code.
nodeLineWidthBorder thickness; see gpar.
nodeLineColorA valid color name or hexadecimal code.
nodeLabelCharacter string (NA will omit labels).
nodeLabelSizeFont size in pts; see gpar.
nodeLabelColorA valid color name or hexadecimal code.

Edge attributes

The following attributes in g are evaluated by the constructor:

edgeLineWidthEdge thickness; see gpar.
edgeLineColorA valid color name or hexadecimal code.
edgeLineTypeLine style (e.g., "solid", "dashed"); see gpar.
arrowTypeArrowhead style (see Arrowhead types section).

Arrowhead types

Arrowheads are controlled via the arrowType attribute using integer or character codes (see examples in the RGraphSpace vignette).

In directed graphs, arrows follow the edge list orientation by default, representing forward directions (e.g., A -> B). While undirected graphs do not show arrows by default, specific styles can be manually assigned for detailed visualization, including forward, backward, or bidirectional arrowheads.

Directed graphs (A -> B):

CodeAliasDescription
0"---"No arrow
1"-->"Forward arrow
-1"--|"Forward bar

Undirected graphs (A – B):

CodeAliasDescription
0"---"No arrow
1"-->"Forward arrow
2"<--"Backward arrow
3"<->"Bidirectional arrow
4"|->"Forward arrow / backward bar
-1"--|"Forward bar
-2"|--"Backward bar
-3"|-|"Bidirectional bar
-4"<-|"Backward arrow / forward bar

Author

Sysbiolab.

Examples

library(igraph)
#> 
#> Attaching package: ‘igraph’
#> The following objects are masked from ‘package:stats’:
#> 
#>     decompose, spectrum
#> The following object is masked from ‘package:base’:
#> 
#>     union

# Create a star graph
gtoy1 <- make_full_graph(15)

# Custom attributes
V(gtoy1)$nodeSize <- 5
E(gtoy1)$edgeLineColor <- "red"
E(gtoy1)$arrowType <- "-->"

# Create a GraphSpace
gs <- GraphSpace(gtoy1)
#> Validating the 'igraph' object...
#> Vertex attributes 'x' and 'y' missing; computing layout...
#> Vertex attribute 'name' missing; assigning names... 
#> Creating a 'GraphSpace' object...