% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/aes-position.R
\name{aes_position}
\alias{aes_position}
\alias{x}
\alias{y}
\alias{xmin}
\alias{xmax}
\alias{ymin}
\alias{ymax}
\alias{xend}
\alias{yend}
\title{Position related aesthetics: x, y, xmin, xmax, ymin, ymax, xend, yend}
\description{
The following aesthetics can be used to specify the position of elements:
\code{x}, \code{y}, \code{xmin}, \code{xmax}, \code{ymin}, \code{ymax}, \code{xend}, \code{yend}.
}
\details{
\code{x} and \code{y} define the locations of points or of positions along a line
or path.

\code{x}, \code{y} and \code{xend}, \code{yend} define the starting and ending points of
segment and curve geometries.

\code{xmin}, \code{xmax}, \code{ymin}  and \code{ymax} can be used to specify the position of
annotations and to represent rectangular areas.

In addition, there are position aesthetics that are contextual to the
geometry that they're used in. These are \code{xintercept}, \code{yintercept},
\code{xmin_final}, \code{ymin_final}, \code{xmax_final}, \code{ymax_final}, \code{xlower}, \code{lower},
\code{xmiddle}, \code{middle}, \code{xupper}, \code{upper}, \code{x0} and \code{y0}. Many of these are used
and automatically computed in \code{\link[=geom_boxplot]{geom_boxplot()}}.
\subsection{Relation to \code{width} and \code{height}}{

The position aesthetics mentioned above like \code{x} and \code{y} are all location
based. The \code{width} and \code{height} aesthetics are closely related length
based aesthetics, but are not position aesthetics. Consequently, \code{x} and \code{y}
aesthetics respond to scale transformations, whereas the length based
\code{width} and \code{height} aesthetics are not transformed by scales. For example,
if we have the pair \verb{x = 10, width = 2}, that gets translated to the
locations \verb{xmin = 9, xmax = 11} when using the default identity scales.
However, the same pair becomes \verb{xmin = 1, xmax = 100} when using log10 scales,
as \code{width = 2} in log10-space spans a 100-fold change.
}
}
\examples{

# Generate data: means and standard errors of means for prices
# for each type of cut
dmod <- lm(price ~ cut, data = diamonds)
cut <- unique(diamonds$cut)
cuts_df <- data.frame(
  cut,
  predict(dmod, data.frame(cut), se = TRUE)[c("fit", "se.fit")]
)
ggplot(cuts_df) +
  aes(
   x = cut,
   y = fit,
   ymin = fit - se.fit,
   ymax = fit + se.fit,
   colour = cut
  ) +
  geom_pointrange()

# Using annotate
p <- ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point()
p
p + annotate(
  "rect", xmin = 2, xmax = 3.5, ymin = 2, ymax = 25,
  fill = "dark grey", alpha = .5
)

# Geom_segment examples
p + geom_segment(
  aes(x = 2, y = 15, xend = 2, yend = 25),
  arrow = arrow(length = unit(0.5, "cm"))
)
p + geom_segment(
  aes(x = 2, y = 15, xend = 3, yend = 15),
  arrow = arrow(length = unit(0.5, "cm"))
)
p + geom_segment(
  aes(x = 5, y = 30, xend = 3.5, yend = 25),
  arrow = arrow(length = unit(0.5, "cm"))
)

# You can also use geom_segment() to recreate plot(type = "h")
# from base R:
set.seed(1)
counts <- as.data.frame(table(x = rpois(100, 5)))
counts$x <- as.numeric(as.character(counts$x))
with(counts, plot(x, Freq, type = "h", lwd = 10))

ggplot(counts, aes(x = x, y = Freq)) +
  geom_segment(aes(yend = 0, xend = x), size = 10)
}
\seealso{
\itemize{
\item Geoms that commonly use these aesthetics: \code{\link[=geom_crossbar]{geom_crossbar()}},
\code{\link[=geom_curve]{geom_curve()}}, \code{\link[=geom_errorbar]{geom_errorbar()}}, \code{\link[=geom_line]{geom_line()}}, \code{\link[=geom_linerange]{geom_linerange()}},
\code{\link[=geom_path]{geom_path()}}, \code{\link[=geom_point]{geom_point()}}, \code{\link[=geom_pointrange]{geom_pointrange()}}, \code{\link[=geom_rect]{geom_rect()}},
\code{\link[=geom_segment]{geom_segment()}}
\item Scales that can be used to modify positions:
\code{\link[=scale_x_continuous]{scale_continuous()}},
\code{\link[=scale_x_discrete]{scale_discrete()}},
\code{\link[=scale_x_binned]{scale_binned()}},
\code{\link[=scale_x_date]{scale_date()}}.
\item See also \code{\link[=annotate]{annotate()}} for placing annotations.
}

Other aesthetics documentation: 
\code{\link{aes}()},
\code{\link{aes_colour_fill_alpha}},
\code{\link{aes_group_order}},
\code{\link{aes_linetype_size_shape}}
}
\concept{aesthetics documentation}
