Accessors and attribute utilities for GraphSpace objects
Source:R/gspace-methods.R
GraphSpace-accessors.RdAccess and modify individual components of a GraphSpace object. Selected igraph methods are applied to the internal graph representation and propagated to downstream node and edge components.
Usage
# S4 method for class 'GraphSpace'
names(x)
# S4 method for class 'GraphSpace'
gs_names(x)
# S4 method for class 'GraphSpace'
gs_nodes(x, ...)
# S4 method for class 'GraphSpace'
gs_edges(x, ...)
# S4 method for class 'GraphSpace'
gs_image(x)
# S4 method for class 'GraphSpace'
gs_image(x) <- value
# S4 method for class 'GraphSpace'
gs_graph(x)
# S4 method for class 'GraphSpace'
gs_fdata(x)
# S4 method for class 'GraphSpace'
gs_fdata(x) <- value
# S4 method for class 'GraphSpace'
gs_nfeatures(x)
# S4 method for class 'GraphSpace'
gs_features(x)
# S4 method for class 'GraphSpace'
gs_vcount(x)
# S4 method for class 'GraphSpace'
gs_ecount(x)
# S4 method for class 'GraphSpace'
gs_vertex_attr(x, name, ...)
# S4 method for class 'GraphSpace'
gs_vertex_attr(x, name, ...) <- value
# S4 method for class 'GraphSpace'
gs_edge_attr(x, name, ...)
# S4 method for class 'GraphSpace'
gs_edge_attr(x, name, ...) <- value
# S4 method for class 'GraphSpace'
x$name
# S4 method for class 'GraphSpace'
x$name <- value
# S3 method for class 'GraphSpace'
as.igraph(x, ...)Arguments
- x
A GraphSpace class object
- ...
Additional arguments passed to extraction methods.
- value
Replacement value for the selected slot or attribute.
- name
Name of the attribute.
Value
Updated GraphSpace object.
Details
For gs_nodes(), the optional vars argument specifies
node-associated features retrieved from the fdata
container. See also gs_fetch_features.
Examples
library(RGraphSpace)
library(igraph)
#>
#> Attaching package: ‘igraph’
#> The following objects are masked from ‘package:stats’:
#>
#> decompose, spectrum
#> The following object is masked from ‘package:base’:
#>
#> union
# Load a demo igraph
data('gtoy1', package = 'RGraphSpace')
# Create a new GraphSpace object
gs <- GraphSpace(gtoy1)
#> Validating the 'igraph' object...
#> Ignoring graph-level attributes: 'name', 'mode', 'center'
#> Creating a 'GraphSpace' object...
#--- Usage of GraphSpace attribute accessors:
# Vertex names
names(gs)
#> [1] "n1" "n2" "n3" "n4" "n5"
# Vertex attribute names
gs_names(gs)
#> [1] "vertex" "x" "y" "name"
#> [5] "nodeLabel" "nodeLabelSize" "nodeLabelColor" "nodeShape"
#> [9] "nodeSize" "nodeColor" "nodeLineWidth" "nodeLineColor"
#> [13] "nodeAlpha"
# Get a data frame with nodes
gs_nodes(gs)
#> vertex x y name nodeLabel nodeLabelSize nodeLabelColor nodeShape nodeSize
#> n1 1 0 0 n1 V1 3 black 21 8
#> n2 2 2 0 n2 V2 3 black 22 5
#> n3 3 -2 2 n3 V3 3 black 23 5
#> n4 4 -4 -4 n4 V4 3 black 24 10
#> n5 5 -8 0 n5 V5 3 black 25 5
#> nodeColor nodeLineWidth nodeLineColor nodeAlpha
#> n1 red 1 grey20 1
#> n2 #00ad39 1 grey20 1
#> n3 grey80 1 grey20 1
#> n4 lightblue 1 grey20 1
#> n5 cyan 1 grey20 1
# Get a data frame with edges
gs_edges(gs)
#> vertex1 vertex2 name1 name2 edgeLineType edgeColor edgeLineWidth arrowType
#> 1 1 2 n1 n2 solid red 0.8 1
#> 2 1 3 n1 n3 11 green 0.8 1
#> 3 1 4 n1 n4 dashed blue 0.8 1
#> 4 1 5 n1 n5 2124 black 0.8 1
#> edgeAlpha curve_weight is_multiple is_loop
#> 1 1 1 FALSE FALSE
#> 2 1 1 FALSE FALSE
#> 3 1 1 FALSE FALSE
#> 4 1 1 FALSE FALSE
# Get vertex count
gs_vcount(gs)
#> [1] 5
# Get edge count
gs_ecount(gs)
#> [1] 4
# Access all vertex attributes
gs_vertex_attr(gs)
#> $x
#> [1] 0 2 -2 -4 -8
#>
#> $y
#> [1] 0 0 2 -4 0
#>
#> $name
#> [1] "n1" "n2" "n3" "n4" "n5"
#>
#> $nodeLabel
#> [1] "V1" "V2" "V3" "V4" "V5"
#>
#> $nodeLabelSize
#> [1] 3 3 3 3 3
#>
#> $nodeLabelColor
#> [1] "black" "black" "black" "black" "black"
#>
#> $nodeShape
#> [1] 21 22 23 24 25
#>
#> $nodeSize
#> [1] 8 5 5 10 5
#>
#> $nodeColor
#> [1] "red" "#00ad39" "grey80" "lightblue" "cyan"
#>
#> $nodeLineWidth
#> [1] 1 1 1 1 1
#>
#> $nodeLineColor
#> [1] "grey20" "grey20" "grey20" "grey20" "grey20"
#>
#> $nodeAlpha
#> [1] 1 1 1 1 1
#>
# Access a specific vertex attribute
gs_vertex_attr(gs, "nodeLabel")
#> n1 n2 n3 n4 n5
#> "V1" "V2" "V3" "V4" "V5"
# Modify a single value within a vertex attribute
gs_vertex_attr(gs, "nodeSize")["n1"] <- 10
# Replace an entire vertex attribute
gs_vertex_attr(gs, "nodeSize") <- 10
# Access a specific edge attribute
gs_edge_attr(gs, "edgeColor")
#> [1] "red" "green" "blue" "black"
# Replace an entire edge attribute
gs_edge_attr(gs, "edgeLineWidth") <- 1
# Add an image and rescale graph coordinates to image space
# Images may be provided as a raster or numeric matrix
gs_image(gs) <- as_colorraster(volcano)
#> Image spatial boundaries:
#> ℹ x: [1, 61] (cols)
#> ℹ y: [1, 87] (rows)
gs <- normalizeGraphSpace(gs, image.space = FALSE)
#> Normalizing node coordinates to graph space...