Skip to contents

gs_image() returns the image shown behind the graph, and gs_image<- sets the source image. gs_image_maxpixels() gets or sets a pixel budget for SpatRaster images.

Usage

# S4 method for class 'GraphSpaceInterface'
gs_image(x)

# S4 method for class 'GraphSpaceInterface'
gs_image(x) <- value

# S4 method for class 'GraphSpaceInterface'
gs_image_maxpixels(x)

# S4 method for class 'GraphSpaceInterface'
gs_image_maxpixels(x) <- value

Arguments

x

A GraphSpace object.

value

For gs_image<-: a raster, a numeric matrix, or a SpatRaster (requires the terra package). For gs_image_maxpixels<-: a single number of at least 1; Inf disables downsampling.

Value

gs_image() returns a raster or a SpatRaster, and gs_image_maxpixels() a single number. The replacement forms return the updated GraphSpace object.

Details

A GraphSpace object keeps its image in two forms:

  • Source image, as set by gs_image<-. Numeric matrices are rescaled to \([0, 1]\) when needed and converted to a raster; SpatRaster objects are stored as they are.

  • Display image, built from the source image when the object is normalized to image space (normalizeGraphSpace(image.space = TRUE)): the region around the nodes, aligned with their positions.

gs_image() returns the display image when available, otherwise the source image. Setting a new image on an object normalized to image space denormalizes it, since its display image and node positions derive from the previous image.

gs_image_maxpixels() limits the size of SpatRaster images: when an image is normalized or plotted, it is downsampled to about that many pixels. Other images are used at full resolution. The default is 4e6.

Examples

library(RGraphSpace)

# A GraphSpace object with an image
data("gs_image_toy", package = "RGraphSpace")
gs <- gs_image_toy
dim(gs_image(gs))
#> [1] 640 680

# Normalized to image space, gs_image() returns the display image
gs <- normalizeGraphSpace(gs, image.space = TRUE)
#> Normalizing node coordinates to image space...
#> Flipping y-coordinates over image center...
dim(gs_image(gs))
#> [1] 376 376

# Set an image from a numeric matrix (rescaled and rasterized)
data("gtoy1", package = "RGraphSpace")
gs1 <- GraphSpace(gtoy1)
#> Validating the 'igraph' object...
#> Ignoring graph-level attributes: 'name', 'mode', 'center'
#> Creating a 'GraphSpace' object...
gs_image(gs1) <- volcano
#> ℹ Rasterizing numeric matrix.
#> • Values outside [0,1] are rescaled before conversion.

# Or from a color raster
gs_image(gs1) <- as_colorraster(volcano)

# Pixel budget for 'SpatRaster' images
gs_image_maxpixels(gs1)
#> [1] 4e+06
gs_image_maxpixels(gs1) <- 1e6