% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/gspace-ggplot-constructor.R
\name{ggplot-GraphSpace}
\alias{ggplot-GraphSpace}
\alias{ggplot.GraphSpace}
\title{Using ggplot2 with GraphSpace objects}
\usage{
\method{ggplot}{GraphSpace}(data, mapping = NULL, ...)
}
\arguments{
\item{data}{A \link{GraphSpace} object.}

\item{mapping}{Set of aesthetic mappings created by \link[ggplot2]{aes}.
Passed to \link[ggplot2]{ggplot}.}

\item{...}{Additional arguments passed to \link[ggplot2]{ggplot}.}
}
\value{
A \code{gspace_plot} object extending \link[ggplot2]{ggplot}.
}
\description{
GraphSpace objects can be used directly with \pkg{ggplot2}, allowing node
attributes and high-dimensional feature data to be mapped through standard
aesthetic mappings without manual data extraction.
This integration enables:
\itemize{
\item Lazy evaluation of node attributes and feature data.
\item Automatic synchronization of node metadata for standard ggplot2
geoms such as \link[ggplot2]{geom_point}.
\item Automatic propagation of node metadata required for edge clipping
and arrow placement in GraphSpace-native geoms.
}
}
\details{
When a GraphSpace object is supplied to \code{ggplot()}, RGraphSpace
extends the standard ggplot2 build process to automatically resolve
GraphSpace variables and synchronize node metadata required for edge
rendering.

When using \code{ggplot()}, neither \link{nodespace_handler} nor
\link{inject_nodespace} need to be called explicitly.
}
\examples{
library(RGraphSpace)
library(igraph)
library(ggplot2)

# Generate a toy star graph
gtoy1 <- make_star(15, mode = "out")
V(gtoy1)$my_node_var <- runif(vcount(gtoy1), 1, 20)

# Create a GraphSpace object
gs <- GraphSpace(gtoy1, layout = layout_in_circle(gtoy1))

\dontrun{

# Example 1: Using RGraphSpace-native geoms
# Edge clipping metadata are injected automatically
ggplot(gs) +
  geom_edgespace(colour = "red") +
  geom_nodespace(aes(size = my_node_var), 
  fill = "steelblue", stroke = 2) +
  scale_size(range = c(2, 15))

# Example 2: Mixing native and general geoms
# Note possible clipping mismatch when combining
# geom_edgespace() with generic ggplot2 node geoms.
# Since geom_point() does not expose the final rendered
# node radius to RGraphSpace, edge clipping is estimated
# from layer parameters and may not exactly match the
# displayed node geometry.
ggplot(gs) +
  geom_edgespace(colour = "red") +
  geom_point(aes(x, y, size = my_node_var), 
  fill = "steelblue", stroke = 2, shape = 21) +
  scale_size(range = c(2, 15))

}

}
\seealso{
\link{GraphSpace}, \link{geom_nodespace}, \link{geom_edgespace},
\link{inject_nodespace}, \link{nodespace_handler}, \link{edgespace_handler}
}
