Skip to contents

annotation_gspace_image() adds an image annotation layer to a ggplot-based GraphSpace plot.

Usage

annotation_gspace_image(
  x,
  interpolate = FALSE,
  opacity = 1,
  flip.v = FALSE,
  flip.h = FALSE,
  na.color = NA,
  rgb_channels = c(1, 2, 3),
  stretch = c("lin", "hist")
)

Arguments

x

An image to be displayed. Accepted types:

interpolate

A logical value indicating whether to apply linear interpolation when the image is rendered at a different resolution than its native size. Defaults to FALSE.

opacity

A numeric value in [0, 1] controlling the transparency of the image. 1 is fully opaque (default); 0 is fully transparent.

flip.v

A logical value; if TRUE, the image is flipped vertically (top-to-bottom). Defaults to FALSE.

flip.h

A logical value; if TRUE, the image is flipped horizontally (left-to-right). Defaults to FALSE.

na.color

The colour to map to NA values. Defaults to NA.

rgb_channels

When a SpatRaster is provided, an integer vector of length 3 giving the layers to use as the red, green, and blue channels. Use NA for an empty channel (e.g. c(3, 2, NA)). Defaults to c(1, 2, 3).

stretch

When a SpatRaster is provided, option to stretch RGB values to increase contrast: "lin" (linear) or "hist" (histogram). To disable, set stretch = NULL. See plotRGB.

Value

A ggplot2 layer object that can be added to a ggplot() call with +, or invisible(NULL) with a warning if the image could not be resolved.

Examples


library(RGraphSpace)
library(igraph)

# Load a demo igraph
data('gtoy1', package = 'RGraphSpace')
gs <- GraphSpace(gtoy1)
#> Validating the 'igraph' object...
#> Ignoring graph-level attributes: 'name', 'mode', 'center'
#> Creating a 'GraphSpace' object...

# Normalize node coordinates
gs <- normalizeGraphSpace(gs)
#> Normalizing node coordinates to graph space...

# Add a raster image
gs_image(gs) <- as_colorraster(volcano)

if (FALSE) { # \dontrun{
# Pass a GraphSpace object directly
ggplot(gs) +
  annotation_gspace_image(gs) +
  geom_edgespace() +
  geom_nodespace()

# Extract the image explicitly
ggplot(gs) +
  annotation_gspace_image(gs_image(gs)) +
  geom_edgespace() +
  geom_nodespace()

# Dim the background and flip vertically
ggplot(gs) +
  annotation_gspace_image(gs, opacity = 0.5, flip.v = TRUE) +
  geom_edgespace() +
  geom_nodespace()
  
} # }