% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/gspace-methods.R
\name{GraphSpace,ANY-method}
\alias{GraphSpace,ANY-method}
\alias{GraphSpace}
\alias{GraphSpace,data.frame-method}
\title{Create a GraphSpace object}
\usage{
\S4method{GraphSpace}{ANY}(g, layout = NULL, verbose = TRUE, ...)

\S4method{GraphSpace}{data.frame}(g, verbose = TRUE, ...)
}
\arguments{
\item{g}{A graph object inheriting from the \link[igraph]{igraph} class
(such as \code{igraph} and \code{tbl_graph}) or a \code{data.frame} used
to initialize a \code{GraphSpace} object. If a graph is provided, it
should include vertex coordinates in \code{x} and \code{y} attributes,
and vertex labels in the \code{name} attribute. If a \code{data.frame}
is provided, it must contain at least \code{x} and \code{y} columns
representing the node coordinates; additional columns will be treated as
vertex attributes. For graphs requiring edge definitions, use the
\code{igraph} initialization.}

\item{layout}{An optional numeric matrix with two columns for \code{x} and
\code{y} vertex coordinates. If provided, it overrides coordinates in \code{g}.}

\item{verbose}{A logical value. If \code{TRUE}, displays detailed messages.}

\item{...}{Additional arguments passed to the \code{GraphSpace} constructor.}
}
\value{
A \linkS4class{GraphSpace} class object.
}
\description{
\code{GraphSpace} is the main constructor for
\linkS4class{GraphSpace} objects, designed to store graph data and
metadata for optimized rendering in RGraphSpace.
}
\details{
\code{GraphSpace} objects are designed to bridge the gap between network
analysis (via \code{igraph}) and high-quality visualization (via \code{ggplot2}).
The constructor ensures that all necessary aesthetics for
\code{\link{geom_graphspace}} are pre-processed and validated.

\strong{Coordinate System and Normalization:}
By default, the constructor expects coordinates in the \code{x} and \code{y}
vertex attributes, along with unique IDs in the \code{name} vertex
attribute. If these are not provided, the constructor will generate
sequential IDs and assign a layout using the
\code{\link[igraph]{layout_nicely}} function. These coordinates define the
relative positioning of nodes. For optimal rendering, it is recommended
to pass the object through \code{\link{normalizeGraphSpace}} after
construction. This converts vertex positions to Normalized Parent Coordinates
(NPC), ensuring the graph remains centered and scaled relative to the
plotting area.

\strong{Data Structure:}
The resulting object stores nodes and edges in separate internal slots,
preserving metadata such as \code{nodeSize} and \code{edgeLineColor}.
If an \code{igraph} object is provided without specific styling attributes,
\code{GraphSpace} will assign the default values defined in the
\code{\link{geom_graphspace}} aesthetics. Users can also specify custom
variables in the input graph to be used as aesthetics within the
\code{ggplot2} grammar.

\strong{Arrowhead Mapping:}
The \code{arrowType} attribute (see \emph{Arrowhead types} section)
allows for a mapping between symbolic aliases (such as \code{"-->"})
and internal integer codes. This is useful for assigning interaction
types in directed or undirected graphs (e.g., activation vs. inhibition).
}
\section{Vertex attributes}{

The following attributes in \code{g} are evaluated by the constructor:

\tabular{ll}{
\code{nodeSize} \tab Numeric \code{[0, 100]}, representing \% of the plotting space. \cr
\code{nodeShape} \tab Integer code \code{[0-25]}; see \link[graphics]{points}. \cr
\code{nodeColor} \tab A valid color name or hexadecimal code. \cr
\code{nodeLineWidth} \tab Border thickness; see \link[grid]{gpar}. \cr
\code{nodeLineColor} \tab A valid color name or hexadecimal code. \cr
\code{nodeLabel} \tab Character string (\code{NA} will omit labels). \cr
\code{nodeLabelSize} \tab Font size in \code{pts}; see \link[grid]{gpar}. \cr
\code{nodeLabelColor} \tab A valid color name or hexadecimal code.
}
}

\section{Edge attributes}{

The following attributes in \code{g} are evaluated by the constructor:

\tabular{ll}{
\code{edgeLineWidth} \tab Edge thickness; see \code{\link[grid]{gpar}}. \cr
\code{edgeLineColor} \tab A valid color name or hexadecimal code. \cr
\code{edgeLineType}  \tab Line style (e.g., "solid", "dashed"); see \code{\link[grid]{gpar}}. \cr
\code{arrowType}     \tab Arrowhead style (see \emph{Arrowhead types} section).
}
}

\section{Arrowhead types}{


Arrowheads are controlled via the \code{arrowType} attribute using
integer or character codes (see examples in the \emph{RGraphSpace} vignette).

In directed graphs, arrows follow the edge list orientation by default,
representing forward directions (\emph{e.g.}, \code{A -> B}).
While undirected graphs do not show arrows by default, specific styles
can be manually assigned for detailed visualization, including forward,
backward, or bidirectional arrowheads.

\subsection{Directed graphs (A -> B):}{
\tabular{lll}{
\strong{Code} \tab \strong{Alias} \tab \strong{Description} \cr
\code{0} \tab \code{"---"} \tab No arrow \cr
\code{1} \tab \code{"-->"} \tab Forward arrow \cr
\code{-1} \tab \code{"--|"} \tab Forward bar
}
}

\subsection{Undirected graphs (A -- B):}{
\tabular{lll}{
\strong{Code} \tab \strong{Alias} \tab \strong{Description} \cr
\code{0} \tab \code{"---"} \tab No arrow \cr
\code{1} \tab \code{"-->"} \tab Forward arrow \cr
\code{2} \tab \code{"<--"} \tab Backward arrow \cr
\code{3} \tab \code{"<->"} \tab Bidirectional arrow \cr
\code{4} \tab \code{"|->"} \tab Forward arrow / backward bar \cr
\code{-1} \tab \code{"--|"} \tab Forward bar \cr
\code{-2} \tab \code{"|--"} \tab Backward bar \cr
\code{-3} \tab \code{"|-|"} \tab Bidirectional bar \cr
\code{-4} \tab \code{"<-|"} \tab Backward arrow / forward bar
}
}
}

\examples{
library(RGraphSpace)
library(igraph)

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

# Custom attributes
V(gtoy1)$nodeSize <- 5
E(gtoy1)$edgeLineColor <- "red"
E(gtoy1)$arrowType <- "-->"

# Create a GraphSpace
gs <- GraphSpace(gtoy1)

}
\seealso{
\code{\link{geom_graphspace}}, \code{\link{plotGraphSpace}}
}
\author{
Sysbiolab.
}
