% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/ggplot2-integration.R
\docType{data}
\name{geom_latex}
\alias{geom_latex}
\alias{GeomLatex}
\title{A ggplot2 geom for LaTeX math labels}
\usage{
geom_latex(
  mapping = NULL,
  data = NULL,
  stat = "identity",
  position = "identity",
  ...,
  fontsize = 11,
  math_font = "",
  lineheight = 1.2,
  max_width = 0,
  input_mode = c("mixed", "math"),
  render_mode = c("typeface", "path"),
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = TRUE
)
}
\arguments{
\item{mapping}{Set of aesthetic mappings created by \code{\link[ggplot2:aes]{aes()}}. If specified and
\code{inherit.aes = TRUE} (the default), it is combined with the default mapping
at the top level of the plot. You must supply \code{mapping} if there is no plot
mapping.}

\item{data}{The data to be displayed in this layer. There are three
options:

If \code{NULL}, the default, the data is inherited from the plot
data as specified in the call to \code{\link[ggplot2:ggplot]{ggplot()}}.

A \code{data.frame}, or other object, will override the plot
data. All objects will be fortified to produce a data frame. See
\code{\link[ggplot2:fortify]{fortify()}} for which variables will be created.

A \code{function} will be called with a single argument,
the plot data. The return value must be a \code{data.frame}, and
will be used as the layer data. A \code{function} can be created
from a \code{formula} (e.g. \code{~ head(.x, 10)}).}

\item{stat}{The statistical transformation to use on the data for this layer.
When using a \verb{geom_*()} function to construct a layer, the \code{stat}
argument can be used to override the default coupling between geoms and
stats. The \code{stat} argument accepts the following:
\itemize{
\item A \code{Stat} ggproto subclass, for example \code{StatCount}.
\item A string naming the stat. To give the stat as a string, strip the
function name of the \code{stat_} prefix. For example, to use \code{stat_count()},
give the stat as \code{"count"}.
\item For more information and other ways to specify the stat, see the
\link[ggplot2:layer_stats]{layer stat} documentation.
}}

\item{position}{A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The \code{position} argument accepts the following:
\itemize{
\item The result of calling a position function, such as \code{position_jitter()}.
This method allows for passing extra arguments to the position.
\item A string naming the position adjustment. To give the position as a
string, strip the function name of the \code{position_} prefix. For example,
to use \code{position_jitter()}, give the position as \code{"jitter"}.
\item For more information and other ways to specify the position, see the
\link[ggplot2:layer_positions]{layer position} documentation.
}}

\item{...}{Other arguments passed to \code{\link[ggplot2]{layer}}.}

\item{fontsize}{Default font size in points. Overridden by the \code{size}
aesthetic if mapped.}

\item{math_font}{Name of the math font to use (e.g., \code{"stix"}).}

\item{lineheight}{Multi-line height multiplier (default 1.2), matching
\code{grid::gpar()} semantics.}

\item{max_width}{Maximum width in big points for automatic line
wrapping (default: 0, no wrapping).}

\item{input_mode}{How \code{tex} is interpreted before being parsed.
\code{"mixed"} wraps the input in \code{\\text{...}} so the string
reads as ordinary text and \code{$...$} (or \code{\\(...\\)}) opens
math mode, matching document-level LaTeX semantics. Useful for labels
that arrive from external sources mixing prose and math without explicit
\code{\\text{}} markers. \code{"math"} (default) is the standard
MicroTeX behaviour --- the whole string is treated as math, so unwrapped
prose renders as spaced math italics. The default can be changed globally via
\code{\link{latex_options}(input_mode = "mixed")}. See \code{\link{latex_wrap}}
for details on the wrapping process.}

\item{render_mode}{Character string: \code{"typeface"} (default) renders
glyphs as native text using the math font, producing
selectable/accessible text in PDF and SVG output.
Bundled math fonts and any registered via \code{\link{load_font}}
are read directly from their OTF files --- no system-wide font
install is required.
Falls back to path mode automatically on devices that lack the
R \eqn{\geq} 4.3 glyph engine (e.g., the base \code{pdf()} device).
For selectable PDF output, prefer \code{\link[grDevices]{cairo_pdf}}.
\code{"path"} renders math symbols as filled vector paths (works on
all devices but text is not selectable in PDF/SVG).}

\item{na.rm}{If \code{FALSE}, the default, missing values are removed with
a warning. If \code{TRUE}, missing values are silently removed.}

\item{show.legend}{logical. Should this layer be included in the legends?
\code{NA}, the default, includes if any aesthetics are mapped.
\code{FALSE} never includes, and \code{TRUE} always includes.
It can also be a named logical vector to finely select the aesthetics to
display. To include legend keys for all levels, even
when no data exists, use \code{TRUE}.  If \code{NA}, all levels are shown in legend,
but unobserved levels are omitted.}

\item{inherit.aes}{If \code{FALSE}, overrides the default aesthetics,
rather than combining with them. This is most useful for helper functions
that define both data and aesthetics and shouldn't inherit behaviour from
the default plot specification, e.g. \code{\link[ggplot2:annotation_borders]{annotation_borders()}}.}
}
\value{
A ggplot2 layer.
}
\description{
Renders LaTeX math expressions as native grid grobs within a ggplot2 plot.
Each label is parsed and laid out by MicroTeX, producing resolution-independent
vector output.
}
\section{Aesthetics}{

\code{geom_latex()} understands the following aesthetics (required aesthetics
are in bold):
\itemize{
\item \strong{\code{x}}
\item \strong{\code{y}}
\item \strong{\code{label}} — LaTeX math string
\item \code{size} — font size in points (default: 11)
\item \code{colour} — text colour (default: \code{"black"})
\item \code{angle} — rotation angle in degrees (default: 0)
\item \code{hjust} — horizontal justification, 0–1 (default: 0.5)
\item \code{vjust} — vertical justification, 0–1 (default: 0.5)
\item \code{alpha} — transparency (default: 1)
}
}

\examples{
\donttest{
if (requireNamespace("ggplot2", quietly = TRUE)) {
  library(ggplot2)
  df <- data.frame(
    x = 1:3, y = 1:3,
    eq = c("x^2", "\\\\frac{a}{b}", "\\\\sum_{i=1}^n x_i")
  )
  ggplot(df, aes(x, y, label = eq)) + geom_latex()

  # Use annotate() for single annotations (no legend, no data frame needed)
  ggplot(mtcars, aes(wt, mpg)) + geom_point() +
    annotate("latex", x = 4, y = 30,
             label = r"($\hat{y} = \beta_0 + \beta_1 x$)")
}
}
}
\keyword{datasets}
