gs_coords() returns the node coordinates of a
GraphSpace object as a two-column matrix, and
gs_coords<- replaces them.
Usage
# S4 method for class 'GraphSpaceInterface'
gs_coords(x, raw = FALSE, unit = NULL)
# S4 method for class 'GraphSpaceInterface'
gs_coords(x, raw = FALSE) <- value
# S4 method for class 'GraphSpaceInterface'
gs_scale_factor(x)
# S4 method for class 'GraphSpaceInterface'
gs_scale_factor(x) <- valueArguments
- x
A GraphSpace object.
- raw
A single logical value. If
FALSE(default), get or set the node positions used for plotting; ifTRUE, the raw node coordinates (see Details).- unit
For
gs_coords(): optional length unit, such as"um"or"mm", to return the coordinates in that unit, using the unit set withgs_coords_unit. Node positions in a physical unit are measured from the origin of the plot space.- value
For
gs_coords<-: a numeric matrix or data frame with two columns (x, y) and one row per node. Columns namedxandyare matched by name, and rows named after nodes are matched by node name; otherwise, both are taken in order. Forgs_scale_factor<-: a single positive number.
Value
gs_coords() returns a numeric matrix with columns x and
y, one row per node, named by node. gs_coords<- returns the
updated GraphSpace object.
Details
A GraphSpace object keeps two sets of node coordinates:
Node positions (
raw = FALSE): the coordinates used for plotting. Normalization transforms them, and they can be edited withgs_coords<-,$or[[without changing the raw coordinates.Raw coordinates (
raw = TRUE): thexandyvertex attributes of the graph, with the scale factor applied. Setting them edits the graph, asgs_vertex_attrdoes, and resets the node positions; a normalized object is denormalized.
normalizeGraphSpace recomputes the node positions from the
raw coordinates, and denormalizeGraphSpace resets them to
the raw coordinates.
The scale factor multiplies the graph's x and y
attributes to give the raw coordinates (default 1). Setting it
recomputes the raw coordinates, and rescales geometries to match, and
resets the node positions; a normalized object is denormalized.
Examples
library(RGraphSpace)
library(igraph)
g <- make_ring(5)
gs <- GraphSpace(g)
#> Validating the 'igraph' object...
#> Vertex attributes 'x' and 'y' missing; computing layout...
#> Vertex attribute 'name' missing; assigning names...
#> Ignoring graph-level attributes: 'name', 'mutual', 'circular'
#> Creating a 'GraphSpace' object...
gs <- normalizeGraphSpace(gs)
#> Normalizing node coordinates to graph space...
# Node positions (used for plotting) and raw coordinates
gs_coords(gs)
#> x y
#> n1 0.7474509 0.8806650
#> n2 0.9000000 0.4075077
#> n3 0.4996354 0.1187012
#> n4 0.1000000 0.4085206
#> n5 0.2537440 0.8812988
gs_coords(gs, raw = TRUE)
#> x y
#> n1 0.62939707 0.8687545
#> n2 1.01766983 -0.3355403
#> n3 -0.00135065 -1.0706195
#> n4 -1.01851515 -0.3329622
#> n5 -0.62720110 0.8703675
# Coordinates in micrometers, once the physical unit is set
gs_coords_unit(gs) <- "um"
gs_coords(gs, raw = TRUE, unit = "um")
#> x y
#> n1 0.62939707 0.8687545
#> n2 1.01766983 -0.3355403
#> n3 -0.00135065 -1.0706195
#> n4 -1.01851515 -0.3329622
#> n5 -0.62720110 0.8703675
# Move one node; raw coordinates are unchanged
xy <- gs_coords(gs)
xy["n1", ] <- c(0.5, 0.5)
gs_coords(gs) <- xy
# Set raw coordinates from a new layout (denormalizes the object)
gs_coords(gs, raw = TRUE) <- layout_in_circle(gs_graph(gs))
#> ℹ Updated raw node positions trigger coordinate denormalization.
gs <- normalizeGraphSpace(gs)
#> Normalizing node coordinates to graph space...
# Apply a scaling factor to node coordinates
gs_scale_factor(gs) <- 0.1
#> Denormalizing graph coordinates...
# Undo scaling
gs_scale_factor(gs) <- 1