| normalizeGeometry,GraphSpace-method | R Documentation |
Two related operations for keeping an sfc geometry column
attached to a GraphSpace's nodes in registration with the node
coordinates, for two different situations.
## S4 method for signature 'GraphSpace'
normalizeGeometry(gs, name = "geometry", verbose = TRUE)
## S4 method for signature 'GraphSpace'
fitGeometry(
gs,
name = "geometry",
use_node_size = TRUE,
persist = TRUE,
verbose = TRUE
)
gs |
A |
name |
Character. Name of the geometry column to operate on. |
verbose |
Logical. Whether to report progress messages. |
use_node_size |
Logical. If |
persist |
Logical; whether the 'fitGeometry' transformation persists
through re-normalization. Defaults |
normalizeGeometry is for geometry that is already spatially
meaningful, with its own coordinates genuinely correspond to the nodes
(e.g. real cell-segmentation boundaries) and only needs realigning
to the current, normalized node frame. It fits a linear regression
between the geometry's centroids and the node coordinates and rescales
the geometry accordingly, warning if the fit is poor (the geometry did
not, in fact, scale linearly with the nodes).
fitGeometry is for geometry that is not yet spatially
related to the nodes, as arbitrary shapes used for node markers. It
repositions every shape so its centroid sits exactly at its node's
coordinates and, when use_node_size = TRUE, also rescales
each shape so its diameter matches nodeSize.
Both require gs to already be normalized (see
normalizeGraphSpace), and both operate on a single named
geometry column, leaving any other geometry columns untouched.
The updated GraphSpace object.
For more information and examples, see the online tutorial:
https://sysbiolab.github.io/RGraphSpace/articles/geometries.html
if (requireNamespace("sf", quietly = TRUE)) {
data('gtoy1', package = 'RGraphSpace')
gs <- normalizeGraphSpace(GraphSpace(gtoy1))
# Set different node sizes to test the geometry fitting
gs$nodeShape <- 1
gs$nodeSize <- seq_len(gs_vcount(gs)) * 5
# fitGeometry(): fit arbitrary shapes to the graph layout,
# positioning them at the nodes and scaling to nodeSize
gs_geometry(gs) <- sfshape_ngons(n = gs_vcount(gs))
gs <- fitGeometry(gs)
ggplot(gs) +
geom_edgespace() +
geom_nodespace(colour = "red") +
geom_sf(aes(geometry = geometry), fill = "lightblue") +
theme_gspace_coords(is_norm = TRUE)
# normalizeGeometry(): shapes already in raw node coordinates,
# realigned to the normalized node frame
raw <- getGraphSpace(gs, "coords")
outlines <- sf::st_sfc(Map(sfshape_ngon, raw$x, raw$y, radius = 1))
gs_geometry(gs, name = "outline") <- outlines
gs <- normalizeGeometry(gs, name = "outline")
ggplot(gs) +
geom_edgespace() +
geom_sf(aes(geometry = outline), fill = "lightblue") +
geom_nodespace(colour = "red", size = 5) +
theme_gspace_coords(is_norm = TRUE)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.