Learn R Programming

RGraphSpace (version 1.5.2)

cropGraphSpace,GraphSpace-method: Crop, rotate, flip, and transpose a GraphSpace

Description

Accessory functions to spatially transform a normalized GraphSpace object. cropGraphSpace() subsets the plotting area to a rectangular region; rotateGraphSpace() rotates by a quarter turn; flipGraphSpace() mirrors horizontally or vertically; transposeGraphSpace() swaps the x and y axes.

Usage

# S4 method for GraphSpace
cropGraphSpace(gs, xmin = 0, xmax = 1, ymin = 0, ymax = 1, verbose = TRUE)

# S4 method for GraphSpace rotateGraphSpace(gs, clockwise = FALSE, verbose = TRUE)

# S4 method for GraphSpace flipGraphSpace(gs, vertical = FALSE, verbose = TRUE)

# S4 method for GraphSpace transposeGraphSpace(gs, verbose = TRUE)

Value

A GraphSpace object with updated nodes

and canvas slots.

Arguments

gs

A normalized GraphSpace object.

xmin

A single number in [0,1] specifying the lower x-boundary of the plotting area.

xmax

A single number in [0,1] specifying the upper x-boundary of the plotting area.

ymin

A single number in [0,1] specifying the lower y-boundary of the plotting area.

ymax

A single number in [0,1] specifying the upper y-boundary of the plotting area.

verbose

A single logical value specifying to display detailed messages (when verbose=TRUE) or not (when verbose=FALSE).

clockwise

A single logical value. If FALSE (default), the 90-degree turn is counter-clockwise; if TRUE, clockwise (rotateGraphSpace only).

vertical

A single logical value. If FALSE (default), the flip is horizontal (mirror left-right); if TRUE, vertical (mirror top-bottom). (flipGraphSpace only).

Details

cropGraphSpace() subsets a normalized graph space to a specific region defined by the cropping boundaries. It recalculates node positions and background image boundaries to maintain spatial consistency after cropping, and drops nodes (and edges) that fall outside the window.

rotateGraphSpace(), flipGraphSpace(), and transposeGraphSpace() are all exact, a coordinate/pixel permutation, with no resampling, no interpolation, and no risk of misaligning nodes against the background image. rotateGraphSpace() is restricted to a single 90-degree turn: apply it again to its own output for 180 or 270 degrees, e.g. rotateGraphSpace(rotateGraphSpace(gs)) for 180 degrees. Combine all three with each other to reach any of the 8 symmetries of a square.

See Also

normalizeGraphSpace

Examples

Run this code
library(RGraphSpace)
library(igraph)

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

# Create a GraphSpace
gs <- GraphSpace(gtoy1)

gs <- normalizeGraphSpace(gs)

gs_crop <- cropGraphSpace(gs, ymax = 0.5)
gs_rot90 <- rotateGraphSpace(gs)
gs_flip <- flipGraphSpace(gs)
gs_t <- transposeGraphSpace(gs)

plotGraphSpace(gs, add.labels = TRUE)

plotGraphSpace(gs_crop, add.labels = TRUE)

Run the code above in your browser using DataLab