% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/gspace-normalize.R
\name{normalizeGraphSpace,GraphSpace,missing-method}
\alias{normalizeGraphSpace,GraphSpace,missing-method}
\alias{normalizeGraphSpace}
\alias{normalizeGraphSpace,GraphSpace,ANY-method}
\alias{cropGraphSpace,GraphSpace-method}
\alias{cropGraphSpace}
\title{Normalize node coordinates to graph and image spaces}
\usage{
normalizeGraphSpace(gs, image = NULL, ...)

\S4method{normalizeGraphSpace}{GraphSpace,ANY}(
  gs,
  image,
  ...,
  mar = 0.1,
  flip.x = FALSE,
  flip.y = FALSE,
  rotate.xy = FALSE,
  flip.v = FALSE,
  flip.h = FALSE,
  verbose = TRUE
)

\S4method{cropGraphSpace}{GraphSpace}(gs, crop.coord = c(0, 1, 0, 1), verbose = TRUE)
}
\arguments{
\item{gs}{A \code{GraphSpace} object to be normalized.}

\item{image}{An optional background image. When provided, \code{x} and
\code{y} coordinates must represent pixel positions in the image matrix.}

\item{...}{Additional arguments passed to specific normalization workflows.}

\item{mar}{A single numeric value in \code{[0, 0.5]} controlling the size of
the outer margins around the graph. Without an image, \code{mar} specifies
symmetric margins as a fraction of the graph space. With an image,
\code{mar} is interpreted as a fraction of the available image margins
surrounding the graph.}

\item{flip.x}{Logical; whether to flip the node coordinates along the x-axis.}

\item{flip.y}{Logical; whether to flip the node coordinates along the y-axis.
Useful for aligning nodes with image backgrounds, which often use an
inverted coordinate system.}

\item{rotate.xy}{Logical; whether to rotate x-y coordinates.}

\item{verbose}{A single logical value specifying to display detailed
messages (when \code{verbose=TRUE}) or not (when \code{verbose=FALSE}).}

\item{flip.v}{Logical; whether to vertically flip the background image
matrix (top-to-bottom) to align with the graph coordinate system.}

\item{flip.h}{Logical; whether to horizontally flip the background image
matrix (left-to-right) to align with the graph coordinate system.}

\item{crop.coord}{An optional numeric vector of length four specifying a
cropping region (xmin, xmax, ymin, ymax), with values in normalized
coordinates \code{[0,1]}.}
}
\value{
A \code{GraphSpace} object with updated \code{nodes}
and \code{image} slots.
}
\description{
Accessory functions to normalize node coordinates in GraphSpace,
either by centering them within the graph boundaries
or by mapping them to pixel coordinates of a background image.
}
\details{
These functions provide different strategies for coordinate transformation:
\itemize{
\item \bold{normalizeGraphSpace}: Re-scales node coordinates to a
\code{[0, 1]} unit square based on the graph's bounding box (when
\code{image} is missing) or maps them to pixel coordinates (when
\code{image} is provided). It handles image-to-graph alignment via
\code{flip.} and \code{rotate.} arguments, used to adjust the graph
origin with the image matrix layout. Users should be aware of the
potential discrepancy between image matrix orientation (top-down) and
graph coordinates (bottom-up). The function attempts to automatically
adjust the y-axis to align the graph's bottom-up coordinates with the
image's top-down layout, but further manual adjustments might be required.
\item \bold{cropGraphSpace}: Subsets the normalized graph space into a
specific region defined by \code{crop.coord}. It recalculates node positions
and background image boundaries to maintain spatial consistency after cropping.
This function requires a previously normalized \code{GraphSpace} object.
}
}
\note{
This is an accessory function typically called during
the preprocessing of \code{GraphSpace} objects before rendering.
}
\examples{
library(igraph)

# Create a star graph
gtoy1 <- make_full_graph(15)

# Create a GraphSpace
gs <- GraphSpace(gtoy1)

gs <- normalizeGraphSpace(gs)

}
