| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/scale_units.R |
| 3 |
\name{scale_units} |
| 4 |
\alias{scale_x_units} |
| 5 |
\alias{scale_y_units} |
| 6 |
\alias{scale_colour_units} |
| 7 |
\alias{scale_color_units} |
| 8 |
\alias{scale_fill_units} |
| 9 |
\alias{scale_alpha_units} |
| 10 |
\alias{scale_size_units} |
| 11 |
\alias{scale_size_area_units} |
| 12 |
\alias{scale_radius_units} |
| 13 |
\alias{scale_linewidth_units} |
| 14 |
\title{Continuous scales for units data} |
| 15 |
\usage{ |
| 16 |
scale_x_units(..., sec.axis = ggplot2::waiver(), unit = NULL) |
| 17 |
|
| 18 |
scale_y_units(..., sec.axis = ggplot2::waiver(), unit = NULL) |
| 19 |
|
| 20 |
scale_colour_units(..., unit = NULL) |
| 21 |
|
| 22 |
scale_color_units(..., unit = NULL) |
| 23 |
|
| 24 |
scale_fill_units(..., unit = NULL) |
| 25 |
|
| 26 |
scale_alpha_units(..., unit = NULL) |
| 27 |
|
| 28 |
scale_size_units(..., unit = NULL) |
| 29 |
|
| 30 |
scale_size_area_units(..., unit = NULL) |
| 31 |
|
| 32 |
scale_radius_units(..., unit = NULL) |
| 33 |
|
| 34 |
scale_linewidth_units(..., unit = NULL) |
| 35 |
} |
| 36 |
\arguments{ |
| 37 |
\item{...}{arguments passed on to the corresponding continuous scale |
| 38 |
(see the manual page for each \code{scale_{type}} for details).} |
| 39 |
|
| 40 |
\item{sec.axis}{\code{\link[ggplot2:sec_axis]{sec_axis()}} is used to specify a secondary axis.} |
| 41 |
|
| 42 |
\item{unit}{A unit specification to use for the guide. If given, the values |
| 43 |
will be converted to this unit before plotting. An error will be thrown if |
| 44 |
the specified unit is incompatible with the unit of the data.} |
| 45 |
} |
| 46 |
\description{ |
| 47 |
These are the default scales for the \code{units} class. These will usually |
| 48 |
be added automatically. To override manually, use \code{scale_{type}_units}. |
| 49 |
} |
| 50 |
\examples{ |
| 51 |
if (requireNamespace("ggplot2", quietly=TRUE)) { |
| 52 |
|
| 53 |
library(ggplot2) |
| 54 |
|
| 55 |
mtcars$consumption <- set_units(mtcars$mpg, mi / gallon) |
| 56 |
mtcars$power <- set_units(mtcars$hp, hp) |
| 57 |
|
| 58 |
# Use units encoded into the data |
| 59 |
ggplot(mtcars) + |
| 60 |
geom_point(aes(power, consumption)) |
| 61 |
|
| 62 |
# Convert units on the fly during plotting |
| 63 |
ggplot(mtcars) + |
| 64 |
geom_point(aes(power, consumption)) + |
| 65 |
scale_x_units(unit = "W") + |
| 66 |
scale_y_units(unit = "km/l") |
| 67 |
|
| 68 |
# Resolve units when transforming data |
| 69 |
ggplot(mtcars) + |
| 70 |
geom_point(aes(power, 1 / consumption)) |
| 71 |
|
| 72 |
# Reverse the y axis |
| 73 |
ggplot(mtcars) + |
| 74 |
geom_point(aes(power, consumption)) + |
| 75 |
scale_y_units(transform="reverse") |
| 76 |
|
| 77 |
} |
| 78 |
} |