geom_edgespace: Draw edge elements in a 2D graph layout

View source: R/geom-edgespace.R

geom_edgespaceR Documentation

Draw edge elements in a 2D graph layout

Description

Constructor for GeomEdgeSpace ggproto objects.

A wrapper around geom_segment that enables direct use of edge attributes stored in GraphSpace objects as aesthetics.

This geom is designed to create edge-level aesthetics such as colour and linewidth, or any custom aesthetics defined in GeomEdgeSpace.

Usage

geom_edgespace(
  mapping = NULL,
  data = NULL,
  stat = StatEdgeSpace,
  position = "identity",
  ...,
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = FALSE,
  arrow_size = 1,
  arrow_offset = 0.01,
  lineend = "butt",
  linejoin = "mitre",
  raster = FALSE,
  dpi = NULL,
  dev = "cairo",
  scale = 1
)

edgespace_handler()

Arguments

mapping

Set of aesthetic mappings created by ggplot2::aes(). These mappings override global aesthetics and are not inherited from the top-level plot.

data

The data to be displayed in this layer. It can be a GraphSpace object, an igraph object, or the edgespace_handler() closure. When NULL (default), a handler is created internally.

stat

The statistical transformation to use on the data. Defaults to identity.

position

Position adjustment, either as a string or the result of a call to a position adjustment function.

...

Additional parameters passed to the underlying drawing function in GeomEdgeSpace.

na.rm

Logical. Should missing values be removed? Defaults to FALSE.

show.legend

Logical or a named logical vector indicating whether this layer should be included in legends.

inherit.aes

Logical. If FALSE (default), the layer will use aesthetics defined in mapping.

arrow_size

Numeric scaling factor controlling arrowhead geometry (see 'drawing' section).

arrow_offset

Numeric value controlling the base offset of arrows at edge endpoints (see 'drawing' section).

lineend

Line end style (round, butt, square). Supplied for compatibility with geom_segment.

linejoin

Line join style (round, mitre, bevel). Supplied for compatibility with geom_segment.

raster

Logical. Should node glyphs be rasterized? Rasterization support is based on rasterise.

dpi

Numeric. Rasterization resolution.

dev

Character. Rasterization backend. One of "cairo", "ragg", "ragg_png", or "cairo_png".

scale

Numeric. Rasterization scaling factor (see rasterise).

Details

arrow_size is a numeric scaling factor controlling arrowhead geometry. The value is interpreted in the same numeric space as line width (lwd), ensuring consistent scaling between edge strokes and arrowheads.

arrow_offset is an additive term that offsets arrow endpoints uniformly in graph space and is bounded by the edge length, in NPC units.

Arrowhead types are specified in the GraphSpace constructor.

Value

A ggplot2 layer that renders edge segments defined by GeomEdgeSpace.

Aesthetics

geom_edgespace() understands geom_segment aesthetics.

If these aesthetics are not explicitly provided in aes(), they are automatically retrieved from the GraphSpace object.

x, y, xend, yend Required (automatically supplied).
colour Edge colour (see aes_colour_fill_alpha).
alpha Transparency (see aes_colour_fill_alpha).
linetype Edge line type (see aes_linetype_size_shape).
linewidth Edge line width (see aes_linetype_size_shape).

Required aesthetics (x, y, xend, yend, ...) are supplied from the GraphSpace object and do not need to be manually mapped.

Additional parameters can be passed to control fixed values for the layer. For example: colour = "grey", linetype = 2, linewidth = 1.

Arrows can be further adjusted by arrow_size and arrow_offset arguments (see details).

Integration with ggraph

geom_edgespace is compatible with the ggraph methods. When used within a ggraph() call, the default edgespace_handler() automatically:

  • Identifies the current layout_ggraph.

  • Extracts the x and y coordinates calculated by ggraph.

  • Reconstructs a temporary GraphSpace object to inject spatial metadata and user-chosen ggraph layout.

See Also

GraphSpace, geom_nodespace, geom_graphspace, geom_segment

Examples

library(RGraphSpace)
library(igraph)
library(ggplot2)

# Load a demo igraph
data('gtoy1', package = 'RGraphSpace')

# Create a GraphSpace object
gs <- GraphSpace(gtoy1)

## Not run: 

ggplot() +
  geom_edgespace(data = gs) +
  geom_nodespace(data = gs) +
  theme(aspect.ratio = 1)


## End(Not run)


RGraphSpace documentation built on June 13, 2026, 9:06 a.m.