% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/axis-text.R
\name{axis_text}
\alias{axis_text}
\title{Annotate axis text}
\usage{
axis_text(
  ...,
  position = NULL,
  xintercept = NULL,
  yintercept = NULL,
  breaks,
  labels = NULL,
  colour = NULL,
  size = NULL,
  family = NULL,
  hjust = NULL,
  vjust = NULL,
  angle = 0,
  length = ggplot2::rel(1)
)
}
\arguments{
\item{...}{Not used. Forces named arguments.}

\item{position}{One of \code{"top"}, \code{"bottom"}, \code{"left"}, or \code{"right"}. Inferred
from \code{xintercept} or \code{yintercept} if not provided.}

\item{xintercept}{For \code{"left"}/\code{"right"} axes: float the axis to this x
position in data coordinates instead of the panel edge.}

\item{yintercept}{For \code{"top"}/\code{"bottom"} axes: float the axis to this y
position in data coordinates instead of the panel edge.}

\item{breaks}{A numeric vector of break positions.}

\item{labels}{One of:
\itemize{
\item \code{NULL} (default) to use break values as labels
\item A character vector the same length as \code{breaks}
\item A function taking break values and returning labels
}}

\item{colour}{Inherits from \code{axis.text} in the set theme.}

\item{size}{Inherits from \code{axis.text} in the set theme.}

\item{family}{Inherits from \code{axis.text} in the set theme.}

\item{hjust, vjust}{Justification. Auto-calculated from \code{position} if \code{NULL}.}

\item{angle}{Text rotation angle. Defaults to \code{0}.}

\item{length}{Offset from the axis edge including tick length and margin.
Supports \code{rel()}. Negative values place labels inside the panel. Defaults
to \code{rel(1)} (theme tick length + text margin).}
}
\value{
A list of ggplot2 annotation layers.
}
\description{
Draws text labels at specified break positions along an axis, with style
defaults taken from the \code{axis.text} element of the set theme. Requires
\code{coord_cartesian(clip = "off")}.
}
\examples{
library(ggplot2)
library(dplyr)

set_theme(
  ggrefine::theme_grey(
    panel_heights = rep(unit(50, "mm"), 100),
    panel_widths = rep(unit(75, "mm"), 100),
  )
)

mtcars |>
  ggplot(aes(x = wt, y = mpg, colour = as.factor(gear), fill = as.factor(gear))) +
  scale_colour_discrete(palette = blends::multiply(get_theme()$palette.colour.discrete)) +
  #clip = "off" is required for axis_text, axis_ticks and axis_bracket
  coord_cartesian(clip = "off") +
  #reference lines and shade
  ggscribe::reference_line(xintercept = 2.4) +
  ggscribe::reference_line(yintercept = 12)  +
  ggscribe::panel_shade(
    xmin = 4,
    xmax = 5,
  ) +
  #top axis
  scale_x_continuous(
    sec.axis = ggscribe::sec_axis_text(
      breaks = c(mean(c(4, 5))),
      labels = c("Range"),
      guide = ggscribe::guide_sec_axis_text(
        angle = 90,
      )
    )
  ) +
  ggscribe::axis_bracket(
    position = "top",
    breaks = c(4, 5),
  ) +
  ggscribe::axis_text(
    position = "top",
    breaks = c(2.4),
    labels = c("Threshold"),
  ) +
  #right axis
  ggscribe::axis_text(
    position = "right",
    breaks = 12,
    labels = "Threshold",
  ) +
  #'geom
  geom_point() +
  #annotations fit plot
  theme(plot.background = element_rect(colour = "grey92"))

}
\seealso{
\code{\link[=axis_line]{axis_line()}}, \code{\link[=axis_ticks]{axis_ticks()}},
\code{\link[=axis_bracket]{axis_bracket()}}, \code{\link[=reference_line]{reference_line()}},
\code{\link[=panel_shade]{panel_shade()}}, \code{\link[=sec_axis_text]{sec_axis_text()}}
}
