Normalize node coordinates to graph and image spaces
Source:R/gspace-normalize.R
normalizeGraphSpace-methods.RdAccessory functions to normalize node coordinates in GraphSpace, either by centering them within the graph boundaries or by mapping them to pixel coordinates of a background image.
Usage
normalizeGraphSpace(gs, image = NULL, ...)
# S4 method for class 'GraphSpace,ANY'
normalizeGraphSpace(
gs,
image,
...,
mar = 0.1,
flip.x = FALSE,
flip.y = FALSE,
rotate.xy = FALSE,
flip.v = TRUE,
flip.h = FALSE,
verbose = TRUE
)
# S4 method for class 'GraphSpace'
cropGraphSpace(gs, crop.coord = c(0, 1, 0, 1), verbose = TRUE)Arguments
- gs
A
GraphSpaceobject to be normalized.- image
An optional background image. When provided,
xandycoordinates must represent pixel positions in the image matrix.- ...
Additional arguments passed to specific normalization workflows.
- mar
A single numeric value in
[0, 0.5]controlling the size of the outer margins around the graph. Without an image,marspecifies symmetric margins as a fraction of the graph space. With an image,maris interpreted as a fraction of the available image margins surrounding the graph.- flip.x
Logical; whether to flip the node coordinates along the x-axis.
- flip.y
Logical; whether to flip the node coordinates along the y-axis.
- rotate.xy
Logical; whether to rotate x-y coordinates.
- verbose
A single logical value specifying to display detailed messages (when
verbose=TRUE) or not (whenverbose=FALSE).- flip.v
Logical; whether to vertically flip the background image matrix (top-to-bottom) to align with the graph coordinate system.
- flip.h
Logical; whether to horizontally flip the background image matrix (left-to-right) to align with the graph coordinate system.
- crop.coord
An optional numeric vector of length four specifying a cropping region (xmin, xmax, ymin, ymax), with values in normalized coordinates
[0,1].
Details
These functions provide different strategies for coordinate transformation:
normalizeGraphSpace: Rescales node coordinates to a
[0, 1]unit square based on the graph's bounding box (whenimageis missing) or maps them to pixel coordinates (whenimageis provided). It handles image-to-graph alignment viaflip.v,flip.h,flip.x,flip.y, androtate.xy, used to adjust the graph origin with the image matrix layout.cropGraphSpace: Subsets the normalized graph space into a specific region defined by
crop.coord. It recalculates node positions and background image boundaries to maintain spatial consistency after cropping. This function requires a previously normalizedGraphSpaceobject.
Note
This is an accessory function typically called during
the preprocessing of GraphSpace objects before rendering.
Examples
library(igraph)
# Create a star graph
gtoy1 <- make_full_graph(15)
# 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...
gs <- normalizeGraphSpace(gs)
#> Normalizing node coordinates to graph space...