1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/scale_units.R
\name{scale_units}
\alias{scale_x_units}
\alias{scale_y_units}
\title{Position scales for units data}
\usage{
scale_x_units(..., guide = ggplot2::waiver(), position = "bottom",
sec.axis = ggplot2::waiver(), unit = NULL)
scale_y_units(..., guide = ggplot2::waiver(), position = "left",
sec.axis = ggplot2::waiver(), unit = NULL)
}
\arguments{
\item{...}{arguments passed on to \code{\link[ggplot2]{continuous_scale}}.}
\item{guide}{A function used to create a guide or its name. See
\code{\link[ggplot2:guides]{guides()}} for more information.}
\item{position}{For position scales, The position of the axis.
\code{left} or \code{right} for y axes, \code{top} or \code{bottom} for x axes.}
\item{sec.axis}{\code{\link[ggplot2:sec_axis]{sec_axis()}} is used to specify a secondary axis.}
\item{unit}{A unit specification to use for the axis. If given, the values
will be converted to this unit before plotting. An error will be thrown if
the specified unit is incompatible with the unit of the data.}
}
\description{
These are the default scales for the \code{units} class. These will usually
be added automatically. To override manually, use \code{scale_*_units}.
}
\examples{
if (requireNamespace("ggplot2", quietly=TRUE)) {
library(ggplot2)
mtcars$consumption <- set_units(mtcars$mpg, mi / gallon)
mtcars$power <- set_units(mtcars$hp, hp)
# Use units encoded into the data
ggplot(mtcars) +
geom_point(aes(power, consumption))
# Convert units on the fly during plotting
ggplot(mtcars) +
geom_point(aes(power, consumption)) +
scale_x_units(unit = "W") +
scale_y_units(unit = "km/l")
# Resolve units when transforming data
ggplot(mtcars) +
geom_point(aes(power, 1 / consumption))
}
}
|