View source: R/gspace-ggplot-constructor.R
| inject_nodespace | R Documentation |
Utility function for RGraphSpace that enables edge layers to scan adjacent nodes and determine their dimensions. This information is used to compute arrow clipping offsets, preventing edge geometry from overlapping node symbols.
inject_nodespace(...)
... |
Additional parameters passed to other methods (currently ignored). |
This function operates in two stages within the ggplot2 workflow:
Capture: It scans the plot layers for a GeomNodeSpace
to extract both mapping variables (from aes()) and static parameters
(specifically size and stroke).
Injection: It locates GeomEdgeSpace layers and injects scale rules, captured mappings, and fixed parameters into the geometry parameters.
This "lazy injection" calculates edge clipping based on the actual scales used by the nodes, even if scales are defined after the layers.
Note: inject_nodespace() must be called last in the ggplot chain to
allow the function to correctly scan all previously added layers and scales.
An object of class inject_nodespace, which interacts with the
ggplot2 + operator.
geom_edgespace, geom_nodespace
library(RGraphSpace)
library(igraph)
library(ggplot2)
# Generate a toy star graph
gtoy1 <- make_star(15, mode="out")
# Set node and edge attributes
V(gtoy1)$my_node_var <- runif(vcount(gtoy1), 1, 20)
E(gtoy1)$my_edge_var <- runif(ecount(gtoy1), 1, 20)
# Create a GraphSpace object with a circular layout
gs <- GraphSpace(gtoy1, layout = layout_in_circle(gtoy1))
## Not run:
# Build the plot
# Note that inject_nodespace() is called at the end to
# synchronize node sizes with edge clipping.
ggplot() +
geom_edgespace(aes(colour = my_edge_var), data = gs) +
geom_nodespace(aes(size = my_node_var), data = gs) +
scale_size(range = c(2, 15)) +
inject_nodespace()
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.