scales/ 0000755 0001762 0000144 00000000000 13656356645 011547 5 ustar ligges users scales/NAMESPACE 0000644 0001762 0000144 00000006765 13655055770 012776 0 ustar ligges users # Generated by roxygen2: do not edit by hand
S3method(fullseq,Date)
S3method(fullseq,POSIXt)
S3method(fullseq,difftime)
S3method(fullseq,numeric)
S3method(lines,trans)
S3method(plot,trans)
S3method(print,trans)
S3method(rescale,"NULL")
S3method(rescale,Date)
S3method(rescale,POSIXt)
S3method(rescale,dist)
S3method(rescale,integer64)
S3method(rescale,logical)
S3method(rescale,numeric)
S3method(rescale_mid,"NULL")
S3method(rescale_mid,Date)
S3method(rescale_mid,POSIXt)
S3method(rescale_mid,dist)
S3method(rescale_mid,integer64)
S3method(rescale_mid,logical)
S3method(rescale_mid,numeric)
S3method(round_any,POSIXct)
S3method(round_any,numeric)
export(ContinuousRange)
export(DiscreteRange)
export(Range)
export(abs_area)
export(alpha)
export(area_pal)
export(as.trans)
export(asn_trans)
export(atanh_trans)
export(boxcox_trans)
export(breaks_extended)
export(breaks_log)
export(breaks_pretty)
export(breaks_width)
export(brewer_pal)
export(cbreaks)
export(censor)
export(col2hcl)
export(col_bin)
export(col_factor)
export(col_numeric)
export(col_quantile)
export(colour_ramp)
export(comma)
export(comma_format)
export(cscale)
export(date_breaks)
export(date_format)
export(date_trans)
export(demo_continuous)
export(demo_datetime)
export(demo_discrete)
export(demo_log10)
export(demo_time)
export(dichromat_pal)
export(discard)
export(div_gradient_pal)
export(dollar)
export(dollar_format)
export(dscale)
export(exp_trans)
export(expand_range)
export(extended_breaks)
export(format_format)
export(fullseq)
export(gradient_n_pal)
export(grey_pal)
export(hms_trans)
export(hue_pal)
export(identity_pal)
export(identity_trans)
export(is.trans)
export(label_bytes)
export(label_comma)
export(label_date)
export(label_date_short)
export(label_dollar)
export(label_math)
export(label_number)
export(label_number_auto)
export(label_number_si)
export(label_ordinal)
export(label_parse)
export(label_percent)
export(label_pvalue)
export(label_scientific)
export(label_time)
export(label_wrap)
export(linetype_pal)
export(log10_trans)
export(log1p_trans)
export(log2_trans)
export(log_breaks)
export(log_trans)
export(logit_trans)
export(manual_pal)
export(math_format)
export(minor_breaks_n)
export(minor_breaks_width)
export(modulus_trans)
export(muted)
export(number)
export(number_bytes)
export(number_bytes_format)
export(number_format)
export(oob_censor)
export(oob_censor_any)
export(oob_discard)
export(oob_keep)
export(oob_squish)
export(oob_squish_any)
export(oob_squish_infinite)
export(ordinal)
export(ordinal_english)
export(ordinal_format)
export(ordinal_french)
export(ordinal_spanish)
export(parse_format)
export(percent)
export(percent_format)
export(pretty_breaks)
export(probability_trans)
export(probit_trans)
export(pseudo_log_trans)
export(pvalue)
export(pvalue_format)
export(reciprocal_trans)
export(regular_minor_breaks)
export(rescale)
export(rescale_max)
export(rescale_mid)
export(rescale_none)
export(rescale_pal)
export(reverse_trans)
export(scientific)
export(scientific_format)
export(seq_gradient_pal)
export(shape_pal)
export(show_col)
export(sqrt_trans)
export(squish)
export(squish_infinite)
export(time_format)
export(time_trans)
export(train_continuous)
export(train_discrete)
export(trans_breaks)
export(trans_format)
export(trans_new)
export(trans_range)
export(unit_format)
export(viridis_pal)
export(wrap_format)
export(yj_trans)
export(zero_range)
importFrom(R6,R6Class)
importFrom(graphics,par)
importFrom(graphics,plot)
importFrom(graphics,rect)
importFrom(graphics,text)
importFrom(lifecycle,deprecate_soft)
importFrom(munsell,mnsl)
scales/LICENSE 0000644 0001762 0000144 00000000061 13010421256 012520 0 ustar ligges users YEAR: 2010-2016
COPYRIGHT HOLDER: Hadley Wickham
scales/README.md 0000644 0001762 0000144 00000007432 13655055706 013025 0 ustar ligges users
# scales
[](https://CRAN.R-project.org/package=scales)
[](https://github.com/r-lib/scales/actions)
[](https://codecov.io/gh/r-lib/scales?branch=master)
One of the most difficult parts of any graphics package is scaling,
converting from data values to perceptual properties. The inverse of
scaling, making guides (legends and axes) that can be used to read the
graph, is often even harder\! The scales packages provides the internal
scaling infrastructure used by [ggplot2](http://ggplot2.tidyverse.org/),
and gives you tools to override the default breaks, labels,
transformations and palettes.
# Installation
``` r
# Scales is installed when you install ggplot2 or the tidyverse.
# But you can install just scales from CRAN:
install.packages("scales")
# Or the development version from Github:
# install.packages("devtools")
devtools::install_github("r-lib/scales")
```
# Usage
## Breaks and labels
The most common use of the scales package is to customise to control the
appearance of axis and legend labels. Use a `break_` function to control
how breaks are generated from the limits, and a `label_` function to
control how breaks are turned in to labels.
``` r
library(ggplot2)
library(dplyr, warn.conflicts = FALSE)
library(lubridate, warn.conflicts = FALSE)
txhousing %>%
mutate(date = make_date(year, month, 1)) %>%
group_by(city) %>%
filter(min(sales) > 5e2) %>%
ggplot(aes(date, sales, group = city)) +
geom_line(na.rm = TRUE) +
scale_x_date(
NULL,
breaks = scales::breaks_width("2 years"),
labels = scales::label_date("'%y")
) +
scale_y_log10(
"Total sales",
labels = scales::label_number_si()
)
```

``` r
economics %>%
filter(date < ymd("1970-01-01")) %>%
ggplot(aes(date, pce)) +
geom_line() +
scale_x_date(NULL,
breaks = scales::breaks_width("3 months"),
labels = scales::label_date_short()
) +
scale_y_continuous("Personal consumption expenditures",
breaks = scales::breaks_extended(8),
labels = scales::label_dollar()
)
```

Generally, I don’t recommend running `library(scales)` because when you
type (e.g.) `scales::label_` autocomplete will provide you with a list
of labelling functions to job your memory.
## Advanced features
Scales colour palettes are used to power the scales in ggplot2, but you
can use them in any plotting system. The following example shows how you
might apply them to a base plot.
``` r
library(scales)
# pull a list of colours from any palette
viridis_pal()(4)
#> [1] "#440154FF" "#31688EFF" "#35B779FF" "#FDE725FF"
# use in combination with baseR `palette()` to set new defaults
palette(brewer_pal(palette = "Set2")(4))
par(mar = c(5, 5, 1, 1))
plot(Sepal.Length ~ Sepal.Width, data = iris, col = Species, pch = 20)
```

scales also gives users the ability to define and apply their own custom
transformation functions for repeated use.
``` r
# use trans_new to build a new transformation
logp3_trans <- trans_new(
name = "logp",
trans = function(x) log(x + 3),
inverse = function(x) exp(x) - 3,
breaks = log_breaks()
)
dsamp <- sample_n(diamonds, 100)
ggplot(dsamp, aes(carat, price, colour = color)) +
geom_point() +
scale_y_continuous(trans = logp3_trans)
```

scales/man/ 0000755 0001762 0000144 00000000000 13656262515 012312 5 ustar ligges users scales/man/unit_format.Rd 0000644 0001762 0000144 00000003572 13641652035 015131 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/labels-retired.R
\name{unit_format}
\alias{unit_format}
\title{Unit labels}
\usage{
unit_format(
accuracy = NULL,
scale = 1,
prefix = "",
unit = "m",
sep = " ",
suffix = paste0(sep, unit),
big.mark = " ",
decimal.mark = ".",
trim = TRUE,
...
)
}
\arguments{
\item{accuracy}{A number to round to. Use (e.g.) \code{0.01} to show 2 decimal
places of precision. If \code{NULL}, the default, uses a heuristic that should
ensure breaks have the minimum number of digits needed to show the
difference between adjacent values.
Applied to rescaled data.}
\item{scale}{A scaling factor: \code{x} will be multiplied by \code{scale} before
formating. This is useful if the underlying data is very small or very
large.}
\item{prefix}{Symbols to display before and after value.}
\item{unit}{The units to append.}
\item{sep}{The separator between the number and the unit label.}
\item{suffix}{Symbols to display before and after value.}
\item{big.mark}{Character used between every 3 digits to separate thousands.}
\item{decimal.mark}{The character to be used to indicate the numeric
decimal point.}
\item{trim}{Logical, if \code{FALSE}, values are right-justified to a common
width (see \code{\link[base:format]{base::format()}}).}
\item{...}{Other arguments passed on to \code{\link[base:format]{base::format()}}.}
}
\description{
\Sexpr[results=rd, stage=render]{lifecycle::badge("retired")}
This function is kept for backward compatiblity; you should either use
\code{\link[=label_number]{label_number()}} or \code{\link[=label_number_si]{label_number_si()}} instead.
}
\examples{
# Label with units
demo_continuous(c(0, 1), labels = unit_format(unit = "m"))
# Labels in kg, but original data in g
km <- unit_format(unit = "km", scale = 1e-3, digits = 2)
demo_continuous(c(0, 2500), labels = km)
}
\keyword{internal}
scales/man/seq_gradient_pal.Rd 0000644 0001762 0000144 00000001370 13641652035 016075 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/pal-gradient.r
\name{seq_gradient_pal}
\alias{seq_gradient_pal}
\title{Sequential colour gradient palette (continuous)}
\usage{
seq_gradient_pal(low = mnsl("10B 4/6"), high = mnsl("10R 4/6"), space = "Lab")
}
\arguments{
\item{low}{colour for low end of gradient.}
\item{high}{colour for high end of gradient.}
\item{space}{colour space in which to calculate gradient. Must be "Lab" -
other values are deprecated.}
}
\description{
Sequential colour gradient palette (continuous)
}
\examples{
x <- seq(0, 1, length.out = 25)
show_col(seq_gradient_pal()(x))
show_col(seq_gradient_pal("white", "black")(x))
library(munsell)
show_col(seq_gradient_pal("white", mnsl("10R 4/6"))(x))
}
scales/man/fullseq.Rd 0000644 0001762 0000144 00000000747 13320151564 014251 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/full-seq.r
\name{fullseq}
\alias{fullseq}
\title{Generate sequence of fixed size intervals covering range.}
\usage{
fullseq(range, size, ...)
}
\arguments{
\item{range}{range}
\item{size}{interval size}
\item{...}{other arguments passed on to methods}
}
\description{
Generate sequence of fixed size intervals covering range.
}
\seealso{
\code{\link[plyr:round_any]{plyr::round_any()}}
}
\keyword{internal}
scales/man/reciprocal_trans.Rd 0000644 0001762 0000144 00000000456 13556361126 016135 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/trans-numeric.r
\name{reciprocal_trans}
\alias{reciprocal_trans}
\title{Reciprocal transformation}
\usage{
reciprocal_trans()
}
\description{
Reciprocal transformation
}
\examples{
plot(reciprocal_trans(), xlim = c(0, 1))
}
scales/man/area_pal.Rd 0000644 0001762 0000144 00000000665 13556361126 014351 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/pal-area.r
\name{area_pal}
\alias{area_pal}
\alias{abs_area}
\title{Area palettes (continuous)}
\usage{
area_pal(range = c(1, 6))
abs_area(max)
}
\arguments{
\item{range}{Numeric vector of length two, giving range of possible sizes.
Should be greater than 0.}
\item{max}{A number representing the maximum size.}
}
\description{
Area palettes (continuous)
}
scales/man/trans_breaks.Rd 0000644 0001762 0000144 00000001547 13556361126 015263 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/breaks-retired.R
\name{trans_breaks}
\alias{trans_breaks}
\title{Pretty breaks on transformed scale}
\usage{
trans_breaks(trans, inv, n = 5, ...)
}
\arguments{
\item{trans}{function of single variable, \code{x}, that given a numeric
vector returns the transformed values}
\item{inv}{inverse of the transformation function}
\item{n}{desired number of ticks}
\item{...}{other arguments passed on to pretty}
}
\description{
\Sexpr[results=rd, stage=render]{lifecycle::badge("retired")}
These often do not produce very attractive breaks.
}
\examples{
trans_breaks("log10", function(x) 10 ^ x)(c(1, 1e6))
trans_breaks("sqrt", function(x) x ^ 2)(c(1, 100))
trans_breaks(function(x) 1 / x, function(x) 1 / x)(c(1, 100))
trans_breaks(function(x) -x, function(x) -x)(c(1, 100))
}
\keyword{internal}
scales/man/label_ordinal.Rd 0000644 0001762 0000144 00000005422 13655052654 015373 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/label-ordinal.R
\name{label_ordinal}
\alias{label_ordinal}
\alias{ordinal_english}
\alias{ordinal_french}
\alias{ordinal_spanish}
\alias{ordinal_format}
\alias{ordinal}
\title{Label ordinal numbers (1st, 2nd, 3rd, etc)}
\usage{
label_ordinal(
prefix = "",
suffix = "",
big.mark = " ",
rules = ordinal_english(),
...
)
ordinal_english()
ordinal_french(gender = c("masculin", "feminin"), plural = FALSE)
ordinal_spanish()
ordinal_format(
prefix = "",
suffix = "",
big.mark = " ",
rules = ordinal_english(),
...
)
ordinal(
x,
prefix = "",
suffix = "",
big.mark = " ",
rules = ordinal_english(),
...
)
}
\arguments{
\item{prefix, suffix}{Symbols to display before and after value.}
\item{big.mark}{Character used between every 3 digits to separate thousands.}
\item{rules}{Named list of regular expressions, matched in order.
Name gives suffix, and value specifies which numbers to match.}
\item{...}{Other arguments passed on to \code{\link[base:format]{base::format()}}.}
\item{gender}{Masculin or feminin gender for French ordinal.}
\item{plural}{Plural or singular for French ordinal.}
\item{x}{A numeric vector to format.}
}
\value{
All \code{label_()} functions return a "labelling" function, i.e. a function that
takes a vector \code{x} and returns a character vector of \code{length(x)} giving a
label for each input value.
Labelling functions are designed to be used with the \code{labels} argument of
ggplot2 scales. The examples demonstrate their use with x scales, but
they work similarly for all scales, including those that generate legends
rather than axes.
}
\description{
Round values to integers and then display as ordinal values (e.g. 1st, 2nd,
3rd). Built-in rules are provided for English, French, and Spanish.
}
\section{Old interface}{
\code{ordinal()} and \code{format_ordinal()} are retired; please use \code{label_ordinal()}
instead.
}
\examples{
demo_continuous(c(1, 5))
demo_continuous(c(1, 5), labels = label_ordinal())
demo_continuous(c(1, 5), labels = label_ordinal(rules = ordinal_french()))
# The rules are just a set of regular expressions that are applied in turn
ordinal_french()
ordinal_english()
# Note that ordinal rounds values, so you may need to adjust the breaks too
demo_continuous(c(1, 10))
demo_continuous(c(1, 10), labels = label_ordinal())
demo_continuous(c(1, 10),
labels = label_ordinal(),
breaks = breaks_width(2)
)
}
\seealso{
Other labels for continuous scales:
\code{\link{label_bytes}()},
\code{\link{label_dollar}()},
\code{\link{label_number_auto}()},
\code{\link{label_number_si}()},
\code{\link{label_parse}()},
\code{\link{label_percent}()},
\code{\link{label_pvalue}()},
\code{\link{label_scientific}()}
}
\concept{labels for continuous scales}
scales/man/hue_pal.Rd 0000644 0001762 0000144 00000001712 13641652035 014211 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/pal-hue.r
\name{hue_pal}
\alias{hue_pal}
\title{Hue palette (discrete)}
\usage{
hue_pal(h = c(0, 360) + 15, c = 100, l = 65, h.start = 0, direction = 1)
}
\arguments{
\item{h}{range of hues to use, in [0, 360]}
\item{c}{chroma (intensity of colour), maximum value varies depending on
combination of hue and luminance.}
\item{l}{luminance (lightness), in [0, 100]}
\item{h.start}{hue to start at}
\item{direction}{direction to travel around the colour wheel,
1 = clockwise, -1 = counter-clockwise}
}
\description{
Hue palette (discrete)
}
\examples{
show_col(hue_pal()(4))
show_col(hue_pal()(9))
show_col(hue_pal(l = 90)(9))
show_col(hue_pal(l = 30)(9))
show_col(hue_pal()(9))
show_col(hue_pal(direction = -1)(9))
show_col(hue_pal()(9))
show_col(hue_pal(h = c(0, 90))(9))
show_col(hue_pal(h = c(90, 180))(9))
show_col(hue_pal(h = c(180, 270))(9))
show_col(hue_pal(h = c(270, 360))(9))
}
scales/man/minor_breaks_width.Rd 0000644 0001762 0000144 00000001541 13655050777 016460 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/minor_breaks.R
\name{minor_breaks_width}
\alias{minor_breaks_width}
\alias{minor_breaks_n}
\title{Minor breaks}
\usage{
minor_breaks_width(width, offset)
minor_breaks_n(n)
}
\arguments{
\item{width}{Distance between each break. Either a number, or for
date/times, a single string of the form "{n} {unit}", e.g. "1 month",
"5 days". Unit can be of one "sec", "min", "hour", "day", "week",
"month", "year".}
\item{offset}{Use if you don't want breaks to start at zero}
\item{n}{number of breaks}
}
\description{
Generate minor breaks between major breaks either spaced with a fixed width,
or having a fixed number.
}
\examples{
demo_log10(c(1, 1e6))
if (FALSE) {
# Requires https://github.com/tidyverse/ggplot2/pull/3591
demo_log10(c(1, 1e6), minor_breaks = minor_breaks_n(10))
}
}
scales/man/label_scientific.Rd 0000644 0001762 0000144 00000005011 13641652035 016047 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/label-scientific.R
\name{label_scientific}
\alias{label_scientific}
\alias{scientific_format}
\alias{scientific}
\title{Label numbers with scientific notation (e.g. 1e05, 1.5e-02)}
\usage{
label_scientific(
digits = 3,
scale = 1,
prefix = "",
suffix = "",
decimal.mark = ".",
trim = TRUE,
...
)
scientific_format(
digits = 3,
scale = 1,
prefix = "",
suffix = "",
decimal.mark = ".",
trim = TRUE,
...
)
scientific(
x,
digits = 3,
scale = 1,
prefix = "",
suffix = "",
decimal.mark = ".",
trim = TRUE,
...
)
}
\arguments{
\item{digits}{Number of digits to show before exponent.}
\item{scale}{A scaling factor: \code{x} will be multiplied by \code{scale} before
formating. This is useful if the underlying data is very small or very
large.}
\item{prefix, suffix}{Symbols to display before and after value.}
\item{decimal.mark}{The character to be used to indicate the numeric
decimal point.}
\item{trim}{Logical, if \code{FALSE}, values are right-justified to a common
width (see \code{\link[base:format]{base::format()}}).}
\item{...}{Other arguments passed on to \code{\link[base:format]{base::format()}}.}
\item{x}{A numeric vector to format.}
}
\value{
All \code{label_()} functions return a "labelling" function, i.e. a function that
takes a vector \code{x} and returns a character vector of \code{length(x)} giving a
label for each input value.
Labelling functions are designed to be used with the \code{labels} argument of
ggplot2 scales. The examples demonstrate their use with x scales, but
they work similarly for all scales, including those that generate legends
rather than axes.
}
\description{
Label numbers with scientific notation (e.g. 1e05, 1.5e-02)
}
\section{Old interface}{
\code{scientific_format()} and \code{scientific()} are retired; please use
\code{label_scientific()}.
}
\examples{
demo_continuous(c(1, 10))
demo_continuous(c(1, 10), labels = label_scientific())
demo_continuous(c(1, 10), labels = label_scientific(digits = 3))
demo_log10(c(1, 1e9))
}
\seealso{
Other labels for continuous scales:
\code{\link{label_bytes}()},
\code{\link{label_dollar}()},
\code{\link{label_number_auto}()},
\code{\link{label_number_si}()},
\code{\link{label_ordinal}()},
\code{\link{label_parse}()},
\code{\link{label_percent}()},
\code{\link{label_pvalue}()}
Other labels for log scales:
\code{\link{label_bytes}()},
\code{\link{label_number_si}()}
}
\concept{labels for continuous scales}
\concept{labels for log scales}
scales/man/log_trans.Rd 0000644 0001762 0000144 00000002200 13556361126 014560 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/trans-numeric.r
\name{log_trans}
\alias{log_trans}
\alias{log10_trans}
\alias{log2_trans}
\alias{log1p_trans}
\alias{pseudo_log_trans}
\title{Log transformations}
\usage{
log_trans(base = exp(1))
log10_trans()
log2_trans()
log1p_trans()
pseudo_log_trans(sigma = 1, base = exp(1))
}
\arguments{
\item{base}{base of logarithm}
\item{sigma}{Scaling factor for the linear part of pseudo-log transformation.}
}
\description{
\itemize{
\item \code{log_trans()}: \code{log(x)}
\item \code{log1p()}: \code{log(x + 1)}
\item \code{pseudo_log_trans()}: smoothly transition to linear scale around 0.
}
}
\examples{
plot(log2_trans(), xlim = c(0, 5))
plot(log_trans(), xlim = c(0, 5))
plot(log10_trans(), xlim = c(0, 5))
plot(log_trans(), xlim = c(0, 2))
plot(log1p_trans(), xlim = c(-1, 1))
# The pseudo-log is defined for all real numbers
plot(pseudo_log_trans(), xlim = c(-5, 5))
lines(log_trans(), xlim = c(0, 5), col = "red")
# For large positives nubmers it's very close to log
plot(pseudo_log_trans(), xlim = c(1, 20))
lines(log_trans(), xlim = c(1, 20), col = "red")
}
scales/man/identity_trans.Rd 0000644 0001762 0000144 00000000475 13556361126 015644 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/trans-numeric.r
\name{identity_trans}
\alias{identity_trans}
\title{Identity transformation (do nothing)}
\usage{
identity_trans()
}
\description{
Identity transformation (do nothing)
}
\examples{
plot(identity_trans(), xlim = c(-1, 1))
}
scales/man/number.Rd 0000644 0001762 0000144 00000003057 13641652035 014070 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/label-number.r
\name{number}
\alias{number}
\title{A low-level numeric formatter}
\usage{
number(
x,
accuracy = NULL,
scale = 1,
prefix = "",
suffix = "",
big.mark = " ",
decimal.mark = ".",
trim = TRUE,
...
)
}
\arguments{
\item{x}{A numeric vector to format.}
\item{accuracy}{A number to round to. Use (e.g.) \code{0.01} to show 2 decimal
places of precision. If \code{NULL}, the default, uses a heuristic that should
ensure breaks have the minimum number of digits needed to show the
difference between adjacent values.
Applied to rescaled data.}
\item{scale}{A scaling factor: \code{x} will be multiplied by \code{scale} before
formating. This is useful if the underlying data is very small or very
large.}
\item{prefix}{Symbols to display before and after value.}
\item{suffix}{Symbols to display before and after value.}
\item{big.mark}{Character used between every 3 digits to separate thousands.}
\item{decimal.mark}{The character to be used to indicate the numeric
decimal point.}
\item{trim}{Logical, if \code{FALSE}, values are right-justified to a common
width (see \code{\link[base:format]{base::format()}}).}
\item{...}{Other arguments passed on to \code{\link[base:format]{base::format()}}.}
}
\value{
A character vector of \code{length(x)}.
}
\description{
This function is a low-level helper that powers many of the labelling
functions. You should generally not need to call it directly unless you
are creating your own labelling function.
}
\keyword{internal}
scales/man/label_date.Rd 0000644 0001762 0000144 00000005504 13641652035 014653 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/label-date.R
\name{label_date}
\alias{label_date}
\alias{label_date_short}
\alias{label_time}
\alias{date_format}
\alias{time_format}
\title{Label date/times}
\usage{
label_date(format = "\%Y-\%m-\%d", tz = "UTC")
label_date_short(format = c("\%Y", "\%b", "\%d", "\%H:\%M"), sep = "\\n")
label_time(format = "\%H:\%M:\%S", tz = "UTC")
date_format(format = "\%Y-\%m-\%d", tz = "UTC")
time_format(format = "\%H:\%M:\%S", tz = "UTC")
}
\arguments{
\item{format}{For \code{date_format()} and \code{time_format()} a date/time format
string using standard POSIX specification. See \code{\link[=strptime]{strptime()}} for details.
For \code{date_short()} a character vector of length 4 giving the format
components to use for year, month, day, and hour respectively.}
\item{tz}{a time zone name, see \code{\link[=timezones]{timezones()}}. Defaults
to UTC}
\item{sep}{Separator to use when combining date formats into a single string.}
}
\value{
All \code{label_()} functions return a "labelling" function, i.e. a function that
takes a vector \code{x} and returns a character vector of \code{length(x)} giving a
label for each input value.
Labelling functions are designed to be used with the \code{labels} argument of
ggplot2 scales. The examples demonstrate their use with x scales, but
they work similarly for all scales, including those that generate legends
rather than axes.
}
\description{
\code{label_date()} and \code{label_time()} label date/times using date/time format
strings. \code{label_date_short()} automatically constructs a short format string
suffiicient to uniquely identify labels. It's inspired by matplotlib's
\href{https://matplotlib.org/api/dates_api.html#matplotlib.dates.ConciseDateFormatter}{\code{ConciseDateFormatter}},
but uses a slightly different approach: \code{ConciseDateFormatter} formats
"firsts" (e.g. first day of month, first day of day) specially;
\code{date_short()} formats changes (e.g. new month, new year) specially.
}
\section{Old interface}{
\code{date_format()} and \code{time_format()} are retired; please use \code{label_date()}
and \code{label_time()} instead.
}
\examples{
date_range <- function(start, days) {
start <- as.POSIXct(start)
c(start, start + days * 24 * 60 * 60)
}
two_months <- date_range("2020-05-01", 60)
demo_datetime(two_months)
demo_datetime(two_months, labels = date_format("\%m/\%d"))
# ggplot2 provides a short-hand:
demo_datetime(two_months, date_labels = "\%m/\%d")
# An alternative labelling system is label_date_short()
demo_datetime(two_months, date_breaks = "7 days", labels = label_date_short())
# This is particularly effective for dense labels
one_year <- date_range("2020-05-01", 365)
demo_datetime(one_year, date_breaks = "month")
demo_datetime(one_year, date_breaks = "month", labels = label_date_short())
}
scales/man/colour_ramp.Rd 0000644 0001762 0000144 00000003747 13560021704 015121 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/colour-ramp.R
\name{colour_ramp}
\alias{colour_ramp}
\title{Fast colour interpolation}
\usage{
colour_ramp(colors, na.color = NA, alpha = TRUE)
}
\arguments{
\item{colors}{Colours to interpolate; must be a valid argument to
\code{\link[grDevices:col2rgb]{grDevices::col2rgb()}}. This can be a character vector of
\code{"#RRGGBB"} or \code{"#RRGGBBAA"}, colour names from
\code{\link[grDevices:colors]{grDevices::colors()}}, or a positive integer that indexes into
\code{\link[grDevices:palette]{grDevices::palette()}}.}
\item{na.color}{The colour to map to \code{NA} values (for example,
\code{"#606060"} for dark grey, or \code{"#00000000"} for transparent) and
values outside of [0,1]. Can itself by \code{NA}, which will simply cause
an \code{NA} to be inserted into the output.}
\item{alpha}{Whether to include alpha transparency channels in interpolation.
If \code{TRUE} then the alpha information is included in the interpolation.
The returned colours will be provided in \code{"#RRGGBBAA"} format when needed,
i.e., in cases where the colour is not fully opaque, so that the \code{"AA"}
part is not equal to \code{"FF"}. Fully opaque colours will be returned in
\code{"#RRGGBB"} format. If \code{FALSE}, the alpha information is discarded
before interpolation and colours are always returned as \code{"#RRGGBB"}.}
}
\value{
A function that takes a numeric vector and returns a character vector
of the same length with RGB or RGBA hex colours.
}
\description{
Returns a function that maps the interval [0,1] to a set of colours.
Interpolation is performed in the CIELAB colour space. Similar to
\code{\link[grDevices]{colorRamp}(space = 'Lab')}, but hundreds of
times faster, and provides results in \code{"#RRGGBB"} (or
\code{"#RRGGBBAA"}) character form instead of RGB colour matrices.
}
\examples{
ramp <- colour_ramp(c("red", "green", "blue"))
show_col(ramp(seq(0, 1, length = 12)))
}
\seealso{
\code{\link[grDevices]{colorRamp}}
}
scales/man/alpha.Rd 0000644 0001762 0000144 00000001050 13556361126 013657 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/colour-manip.r
\name{alpha}
\alias{alpha}
\title{Modify colour transparency}
\usage{
alpha(colour, alpha = NA)
}
\arguments{
\item{colour}{colour}
\item{alpha}{new alpha level in [0,1]. If alpha is \code{NA},
existing alpha values are preserved.}
}
\description{
Vectorised in both colour and alpha.
}
\examples{
alpha("red", 0.1)
alpha(colours(), 0.5)
alpha("red", seq(0, 1, length.out = 10))
alpha(c("first" = "gold", "second" = "lightgray", "third" = "#cd7f32"), .5)
}
scales/man/col_numeric.Rd 0000644 0001762 0000144 00000012573 13641652035 015102 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/colour-mapping.r
\name{col_numeric}
\alias{col_numeric}
\alias{col_bin}
\alias{col_quantile}
\alias{col_factor}
\title{Colour mapping}
\usage{
col_numeric(
palette,
domain,
na.color = "#808080",
alpha = FALSE,
reverse = FALSE
)
col_bin(
palette,
domain,
bins = 7,
pretty = TRUE,
na.color = "#808080",
alpha = FALSE,
reverse = FALSE,
right = FALSE
)
col_quantile(
palette,
domain,
n = 4,
probs = seq(0, 1, length.out = n + 1),
na.color = "#808080",
alpha = FALSE,
reverse = FALSE,
right = FALSE
)
col_factor(
palette,
domain,
levels = NULL,
ordered = FALSE,
na.color = "#808080",
alpha = FALSE,
reverse = FALSE
)
}
\arguments{
\item{palette}{The colours or colour function that values will be mapped to}
\item{domain}{The possible values that can be mapped.
For \code{col_numeric} and \code{col_bin}, this can be a simple numeric
range (e.g. \code{c(0, 100)}); \code{col_quantile} needs representative
numeric data; and \code{col_factor} needs categorical data.
If \code{NULL}, then whenever the resulting colour function is called, the
\code{x} value will represent the domain. This implies that if the function
is invoked multiple times, the encoding between values and colours may not
be consistent; if consistency is needed, you must provide a non-\code{NULL}
domain.}
\item{na.color}{The colour to return for \code{NA} values. Note that
\code{na.color = NA} is valid.}
\item{alpha}{Whether alpha channels should be respected or ignored. If \code{TRUE}
then colors without explicit alpha information will be treated as fully
opaque.}
\item{reverse}{Whether the colors (or color function) in \code{palette} should be
used in reverse order. For example, if the default order of a palette goes
from blue to green, then \code{reverse = TRUE} will result in the colors going
from green to blue.}
\item{bins}{Either a numeric vector of two or more unique cut points or a
single number (greater than or equal to 2) giving the number of intervals
into which the domain values are to be cut.}
\item{pretty}{Whether to use the function \code{\link[=pretty]{pretty()}} to generate
the bins when the argument \code{bins} is a single number. When
\code{pretty = TRUE}, the actual number of bins may not be the number of
bins you specified. When \code{pretty = FALSE}, \code{\link[=seq]{seq()}} is used
to generate the bins and the breaks may not be "pretty".}
\item{right}{parameter supplied to \code{\link[base:cut]{base::cut()}}. See Details}
\item{n}{Number of equal-size quantiles desired. For more precise control,
use the \code{probs} argument instead.}
\item{probs}{See \code{\link[stats:quantile]{stats::quantile()}}. If provided, the \code{n}
argument is ignored.}
\item{levels}{An alternate way of specifying levels; if specified, domain is
ignored}
\item{ordered}{If \code{TRUE} and \code{domain} needs to be coerced to a
factor, treat it as already in the correct order}
}
\value{
A function that takes a single parameter \code{x}; when called with a
vector of numbers (except for \code{col_factor}, which expects
factors/characters), #RRGGBB colour strings are returned (unless
\code{alpha = TRUE} in which case #RRGGBBAA may also be possible).
}
\description{
Conveniently maps data values (numeric or factor/character) to colours
according to a given palette, which can be provided in a variety of formats.
}
\details{
\code{col_numeric} is a simple linear mapping from continuous numeric data
to an interpolated palette.
\code{col_bin} also maps continuous numeric data, but performs
binning based on value (see the \code{\link[base:cut]{base::cut()}} function). \code{col_bin}
defaults for the \code{cut} function are \code{include.lowest = TRUE} and
\code{right = FALSE}.
\code{col_quantile} similarly bins numeric data, but via the
\code{\link[stats:quantile]{stats::quantile()}} function.
\code{col_factor} maps factors to colours. If the palette is
discrete and has a different number of colours than the number of factors,
interpolation is used.
The \code{palette} argument can be any of the following:
\enumerate{
\item{A character vector of RGB or named colours. Examples: \code{palette()}, \code{c("#000000", "#0000FF", "#FFFFFF")}, \code{topo.colors(10)}}
\item{The name of an RColorBrewer palette, e.g. \code{"BuPu"} or \code{"Greens"}.}
\item{The full name of a viridis palette: \code{"viridis"}, \code{"magma"}, \code{"inferno"}, or \code{"plasma"}.}
\item{A function that receives a single value between 0 and 1 and returns a colour. Examples: \code{colorRamp(c("#000000", "#FFFFFF"), interpolate="spline")}.}
}
}
\examples{
pal <- col_bin("Greens", domain = 0:100)
show_col(pal(sort(runif(10, 60, 100))))
# Exponential distribution, mapped continuously
show_col(col_numeric("Blues", domain = NULL)(sort(rexp(16))))
# Exponential distribution, mapped by interval
show_col(col_bin("Blues", domain = NULL, bins = 4)(sort(rexp(16))))
# Exponential distribution, mapped by quantile
show_col(col_quantile("Blues", domain = NULL)(sort(rexp(16))))
# Categorical data; by default, the values being coloured span the gamut...
show_col(col_factor("RdYlBu", domain = NULL)(LETTERS[1:5]))
# ...unless the data is a factor, without droplevels...
show_col(col_factor("RdYlBu", domain = NULL)(factor(LETTERS[1:5], levels=LETTERS)))
# ...or the domain is stated explicitly.
show_col(col_factor("RdYlBu", levels = LETTERS)(LETTERS[1:5]))
}
scales/man/rescale.Rd 0000644 0001762 0000144 00000002504 13641652035 014212 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/bounds.r
\name{rescale}
\alias{rescale}
\alias{rescale.numeric}
\alias{rescale.dist}
\alias{rescale.logical}
\alias{rescale.POSIXt}
\alias{rescale.Date}
\alias{rescale.integer64}
\title{Rescale continuous vector to have specified minimum and maximum}
\usage{
rescale(x, to, from, ...)
\method{rescale}{numeric}(x, to = c(0, 1), from = range(x, na.rm = TRUE, finite = TRUE), ...)
\method{rescale}{dist}(x, to = c(0, 1), from = range(x, na.rm = TRUE, finite = TRUE), ...)
\method{rescale}{logical}(x, to = c(0, 1), from = range(x, na.rm = TRUE, finite = TRUE), ...)
\method{rescale}{POSIXt}(x, to = c(0, 1), from = range(x, na.rm = TRUE, finite = TRUE), ...)
\method{rescale}{Date}(x, to = c(0, 1), from = range(x, na.rm = TRUE, finite = TRUE), ...)
\method{rescale}{integer64}(x, to = c(0, 1), from = range(x, na.rm = TRUE), ...)
}
\arguments{
\item{x}{continuous vector of values to manipulate.}
\item{to}{output range (numeric vector of length two)}
\item{from}{input range (vector of length two). If not given, is
calculated from the range of \code{x}}
\item{...}{other arguments passed on to methods}
}
\description{
Rescale continuous vector to have specified minimum and maximum
}
\examples{
rescale(1:100)
rescale(runif(50))
rescale(1)
}
\keyword{manip}
scales/man/label_number_auto.Rd 0000644 0001762 0000144 00000002635 13641652035 016260 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/label-number-auto.R
\name{label_number_auto}
\alias{label_number_auto}
\title{Label numbers, avoiding scientific notation where possible}
\usage{
label_number_auto()
}
\description{
Switches between \code{\link[=number_format]{number_format()}} and \code{\link[=scientific_format]{scientific_format()}} based on a set of
heuristics designed to automatically generate useful labels across a wide
range of inputs
}
\examples{
# Very small and very large numbers get scientific notation
demo_continuous(c(0, 1e-6), labels = label_number_auto())
demo_continuous(c(0, 1e9), labels = label_number_auto())
# Other ranges get the numbers printed in full
demo_continuous(c(0, 1e-3), labels = label_number_auto())
demo_continuous(c(0, 1), labels = label_number_auto())
demo_continuous(c(0, 1e3), labels = label_number_auto())
demo_continuous(c(0, 1e6), labels = label_number_auto())
# Transformation is applied individually so you get as little
# scientific notation as possible
demo_log10(c(1, 1e7), labels = label_number_auto())
}
\seealso{
Other labels for continuous scales:
\code{\link{label_bytes}()},
\code{\link{label_dollar}()},
\code{\link{label_number_si}()},
\code{\link{label_ordinal}()},
\code{\link{label_parse}()},
\code{\link{label_percent}()},
\code{\link{label_pvalue}()},
\code{\link{label_scientific}()}
}
\concept{labels for continuous scales}
scales/man/reverse_trans.Rd 0000644 0001762 0000144 00000000435 13556361126 015462 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/trans-numeric.r
\name{reverse_trans}
\alias{reverse_trans}
\title{Reverse transformation}
\usage{
reverse_trans()
}
\description{
Reverse transformation
}
\examples{
plot(reverse_trans(), xlim = c(-1, 1))
}
scales/man/brewer_pal.Rd 0000644 0001762 0000144 00000002001 13556361126 014711 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/pal-brewer.r
\name{brewer_pal}
\alias{brewer_pal}
\title{Colour Brewer palette (discrete)}
\usage{
brewer_pal(type = "seq", palette = 1, direction = 1)
}
\arguments{
\item{type}{One of seq (sequential), div (diverging) or qual (qualitative)}
\item{palette}{If a string, will use that named palette. If a number, will
index into the list of palettes of appropriate \code{type}}
\item{direction}{Sets the order of colours in the scale. If 1, the default,
colours are as output by \code{\link[RColorBrewer:brewer.pal]{RColorBrewer::brewer.pal()}}. If -1, the
order of colours is reversed.}
}
\description{
Colour Brewer palette (discrete)
}
\examples{
show_col(brewer_pal()(10))
show_col(brewer_pal("div")(5))
show_col(brewer_pal(palette = "Greens")(5))
# Can use with gradient_n to create a continous gradient
cols <- brewer_pal("div")(5)
show_col(gradient_n_pal(cols)(seq(0, 1, length.out = 30)))
}
\references{
\url{http://colorbrewer2.org}
}
scales/man/oob.Rd 0000644 0001762 0000144 00000007470 13655052654 013370 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/bounds.r
\name{oob}
\alias{oob}
\alias{oob_censor}
\alias{oob_censor_any}
\alias{oob_discard}
\alias{oob_squish}
\alias{oob_squish_any}
\alias{oob_squish_infinite}
\alias{oob_keep}
\alias{censor}
\alias{discard}
\alias{squish}
\alias{squish_infinite}
\title{Out of bounds handling}
\usage{
oob_censor(x, range = c(0, 1), only.finite = TRUE)
oob_censor_any(x, range = c(0, 1))
oob_discard(x, range = c(0, 1))
oob_squish(x, range = c(0, 1), only.finite = TRUE)
oob_squish_any(x, range = c(0, 1))
oob_squish_infinite(x, range = c(0, 1))
oob_keep(x, range = c(0, 1))
censor(x, range = c(0, 1), only.finite = TRUE)
discard(x, range = c(0, 1))
squish(x, range = c(0, 1), only.finite = TRUE)
squish_infinite(x, range = c(0, 1))
}
\arguments{
\item{x}{A numeric vector of values to modify.}
\item{range}{A numeric vector of length two giving the minimum and maximum
limit of the desired output range respectively.}
\item{only.finite}{A logical of length one. When \code{TRUE}, only finite values
are altered. When \code{FALSE}, also infinite values are altered.}
}
\value{
Most \code{oob_()} functions return a vector of numerical values of the
same length as the \code{x} argument, wherein out of bounds values have been
modified. Only \code{oob_discard()} returns a vector of less than or of equal
length to the \code{x} argument.
}
\description{
This set of functions modify data values outside a given range.
The \verb{oob_*()} functions are designed to be passed as the \code{oob} argument of
ggplot2 continuous and binned scales, with \code{oob_discard} being an exception.
These functions affect out of bounds values in the following ways:
\itemize{
\item \code{oob_censor()} replaces out of bounds values with \code{NA}s. This is the
default \code{oob} argument for continuous scales.
\item \code{oob_censor_any()} acts like \code{oob_censor()}, but also replaces infinite
values with \code{NA}s.
\item \code{oob_squish()} replaces out of bounds values with the nearest limit. This
is the default \code{oob} argument for binned scales.
\item \code{oob_squish_any()} acts like \code{oob_squish()}, but also replaces infinite
values with the nearest limit.
\item \code{oob_squish_infinite()} only replaces infinite values by the nearest limit.
\item \code{oob_keep()} does not adjust out of bounds values. In position scales,
behaves as zooming limits without data removal.
\item \code{oob_discard()} removes out of bounds values from the input. Not suitable
for ggplot2 scales.
}
}
\details{
The \code{oob_censor_any()} and \code{oob_squish_any()} functions are the same
as \code{oob_censor()} and \code{oob_squish()} with the \code{only.finite} argument set to
\code{FALSE}.
Replacing position values with \code{NA}s, as \code{oob_censor()} does, will typically
lead to removal of those datapoints in ggplot.
Setting ggplot coordinate limits is equivalent to using \code{oob_keep()} in
position scales.
}
\section{Old interface}{
\code{censor()}, \code{squish()}, \code{squish_infinite()} and
\code{discard()} are no longer recommended; please use \code{oob_censor()},
\code{oob_squish()}, \code{oob_squish_infinite()} and \code{oob_discard()} instead.
}
\examples{
# Censoring replaces out of bounds values with NAs
oob_censor(c(-Inf, -1, 0.5, 1, 2, NA, Inf))
oob_censor_any(c(-Inf, -1, 0.5, 1, 2, NA, Inf))
# Squishing replaces out of bounds values with the nearest range limit
oob_squish(c(-Inf, -1, 0.5, 1, 2, NA, Inf))
oob_squish_any(c(-Inf, -1, 0.5, 1, 2, NA, Inf))
oob_squish_infinite(c(-Inf, -1, 0.5, 1, 2, NA, Inf))
# Keeping does not alter values
oob_keep(c(-Inf, -1, 0.5, 1, 2, NA, Inf))
# Discarding will remove out of bounds values
oob_discard(c(-Inf, -1, 0.5, 1, 2, NA, Inf))
}
\author{
\code{oob_squish()}: Homer Strong \href{mailto:homer.strong@gmail.com}{homer.strong@gmail.com}
}
scales/man/label_parse.Rd 0000644 0001762 0000144 00000004145 13641652035 015050 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/label-expression.R
\name{label_parse}
\alias{label_parse}
\alias{label_math}
\alias{parse_format}
\alias{math_format}
\title{Label with mathematical annotations}
\usage{
label_parse()
label_math(expr = 10^.x, format = force)
parse_format()
math_format(expr = 10^.x, format = force)
}
\arguments{
\item{expr}{expression to use}
\item{format}{another format function to apply prior to mathematical
transformation - this makes it easier to use floating point numbers in
mathematical expressions.}
}
\value{
All \code{label_()} functions return a "labelling" function, i.e. a function that
takes a vector \code{x} and returns a character vector of \code{length(x)} giving a
label for each input value.
Labelling functions are designed to be used with the \code{labels} argument of
ggplot2 scales. The examples demonstrate their use with x scales, but
they work similarly for all scales, including those that generate legends
rather than axes.
}
\description{
\code{label_parse()} produces expression from strings by parsing them;
\code{label_math()} constructs expressions by replacing the pronoun \code{.x}
with each string.
}
\section{Old interface}{
\code{parse_format()} and \code{math_format()} was retired; please use
\code{label_parse()} and \code{label_math()} instead.
}
\examples{
# Use label_parse() with discrete scales
greek <- c("alpha", "beta", "gamma")
demo_discrete(greek)
demo_discrete(greek, labels = label_parse())
# Use label_math() with continuous scales
demo_continuous(c(1, 5))
demo_continuous(c(1, 5), labels = label_math(alpha[.x]))
}
\seealso{
\link{plotmath} for the details of mathematical formatting in R.
Other labels for continuous scales:
\code{\link{label_bytes}()},
\code{\link{label_dollar}()},
\code{\link{label_number_auto}()},
\code{\link{label_number_si}()},
\code{\link{label_ordinal}()},
\code{\link{label_percent}()},
\code{\link{label_pvalue}()},
\code{\link{label_scientific}()}
Other labels for discrete scales:
\code{\link{label_wrap}()}
}
\concept{labels for continuous scales}
\concept{labels for discrete scales}
scales/man/probability_trans.Rd 0000644 0001762 0000144 00000001323 13556361126 016324 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/trans-numeric.r
\name{probability_trans}
\alias{probability_trans}
\alias{logit_trans}
\alias{probit_trans}
\title{Probability transformation}
\usage{
probability_trans(distribution, ...)
logit_trans()
probit_trans()
}
\arguments{
\item{distribution}{probability distribution. Should be standard R
abbreviation so that "p" + distribution is a valid probability density
function, and "q" + distribution is a valid quantile function.}
\item{...}{other arguments passed on to distribution and quantile functions}
}
\description{
Probability transformation
}
\examples{
plot(logit_trans(), xlim = c(0, 1))
plot(probit_trans(), xlim = c(0, 1))
}
scales/man/label_dollar.Rd 0000644 0001762 0000144 00000006445 13641652035 015220 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/label-dollar.R
\name{label_dollar}
\alias{label_dollar}
\alias{dollar_format}
\alias{dollar}
\title{Label currencies ($100, $2.50, etc)}
\usage{
label_dollar(
accuracy = NULL,
scale = 1,
prefix = "$",
suffix = "",
big.mark = ",",
decimal.mark = ".",
trim = TRUE,
largest_with_cents = 1e+05,
negative_parens = FALSE,
...
)
dollar_format(
accuracy = NULL,
scale = 1,
prefix = "$",
suffix = "",
big.mark = ",",
decimal.mark = ".",
trim = TRUE,
largest_with_cents = 1e+05,
negative_parens = FALSE,
...
)
dollar(
x,
accuracy = NULL,
scale = 1,
prefix = "$",
suffix = "",
big.mark = ",",
decimal.mark = ".",
trim = TRUE,
largest_with_cents = 1e+05,
negative_parens = FALSE,
...
)
}
\arguments{
\item{accuracy, largest_with_cents}{Number to round to. If \code{NULL}, the default,
values will be rounded to the nearest integer, unless any of the
values has non-zero fractional component (e.g. cents) and the largest
value is less than \code{largest_with_cents} which by default is 100,000.}
\item{scale}{A scaling factor: \code{x} will be multiplied by \code{scale} before
formating. This is useful if the underlying data is very small or very
large.}
\item{prefix, suffix}{Symbols to display before and after value.}
\item{big.mark}{Character used between every 3 digits to separate thousands.}
\item{decimal.mark}{The character to be used to indicate the numeric
decimal point.}
\item{trim}{Logical, if \code{FALSE}, values are right-justified to a common
width (see \code{\link[base:format]{base::format()}}).}
\item{negative_parens}{Display negative using parentheses?}
\item{...}{Other arguments passed on to \code{\link[base:format]{base::format()}}.}
\item{x}{A numeric vector}
}
\value{
All \code{label_()} functions return a "labelling" function, i.e. a function that
takes a vector \code{x} and returns a character vector of \code{length(x)} giving a
label for each input value.
Labelling functions are designed to be used with the \code{labels} argument of
ggplot2 scales. The examples demonstrate their use with x scales, but
they work similarly for all scales, including those that generate legends
rather than axes.
}
\description{
Format numbers as currency, rounding values to dollars or cents using
a convenient heuristic.
}
\section{Old interface}{
\code{dollar()} and \code{format_dollar()} are retired; please use \code{label_dollar()}
instead.
}
\examples{
demo_continuous(c(0, 1), labels = label_dollar())
demo_continuous(c(1, 100), labels = label_dollar())
# Customise currency display with prefix and suffix
demo_continuous(c(1, 100), labels = label_dollar(prefix = "USD "))
euro <- dollar_format(
prefix = "",
suffix = "\u20ac",
big.mark = ".",
decimal.mark = ","
)
demo_continuous(c(1000, 1100), labels = euro)
# Use negative_parens = TRUE for finance style display
demo_continuous(c(-100, 100), labels = label_dollar(negative_parens = TRUE))
}
\seealso{
Other labels for continuous scales:
\code{\link{label_bytes}()},
\code{\link{label_number_auto}()},
\code{\link{label_number_si}()},
\code{\link{label_ordinal}()},
\code{\link{label_parse}()},
\code{\link{label_percent}()},
\code{\link{label_pvalue}()},
\code{\link{label_scientific}()}
}
\concept{labels for continuous scales}
scales/man/show_col.Rd 0000644 0001762 0000144 00000001525 13655054675 014426 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/colour-manip.r
\name{show_col}
\alias{show_col}
\title{Show colours}
\usage{
show_col(colours, labels = TRUE, borders = NULL, cex_label = 1, ncol = NULL)
}
\arguments{
\item{colours}{A character vector of colours}
\item{labels}{Label each colour with its hex name?}
\item{borders}{Border colour for each tile. Default uses \code{par("fg")}.
Use \code{border = NA} to omit borders.}
\item{cex_label}{Size of printed labels, as multiplier of default size.}
\item{ncol}{Number of columns. If not supplied, tries to be as square as
possible.}
}
\description{
A quick and dirty way to show colours in a plot.
}
\examples{
show_col(hue_pal()(9))
show_col(hue_pal()(9), borders = NA)
show_col(viridis_pal()(16))
show_col(viridis_pal()(16), labels = FALSE)
}
\keyword{internal}
scales/man/rescale_mid.Rd 0000644 0001762 0000144 00000002626 13641652035 015050 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/bounds.r
\name{rescale_mid}
\alias{rescale_mid}
\alias{rescale_mid.numeric}
\alias{rescale_mid.logical}
\alias{rescale_mid.dist}
\alias{rescale_mid.POSIXt}
\alias{rescale_mid.Date}
\alias{rescale_mid.integer64}
\title{Rescale vector to have specified minimum, midpoint, and maximum}
\usage{
rescale_mid(x, to, from, mid, ...)
\method{rescale_mid}{numeric}(x, to = c(0, 1), from = range(x, na.rm = TRUE), mid = 0, ...)
\method{rescale_mid}{logical}(x, to = c(0, 1), from = range(x, na.rm = TRUE), mid = 0, ...)
\method{rescale_mid}{dist}(x, to = c(0, 1), from = range(x, na.rm = TRUE), mid = 0, ...)
\method{rescale_mid}{POSIXt}(x, to = c(0, 1), from = range(x, na.rm = TRUE), mid, ...)
\method{rescale_mid}{Date}(x, to = c(0, 1), from = range(x, na.rm = TRUE), mid, ...)
\method{rescale_mid}{integer64}(x, to = c(0, 1), from = range(x, na.rm = TRUE), mid = 0, ...)
}
\arguments{
\item{x}{vector of values to manipulate.}
\item{to}{output range (numeric vector of length two)}
\item{from}{input range (vector of length two). If not given, is
calculated from the range of \code{x}}
\item{mid}{mid-point of input range}
\item{...}{other arguments passed on to methods}
}
\description{
Rescale vector to have specified minimum, midpoint, and maximum
}
\examples{
rescale_mid(1:100, mid = 50.5)
rescale_mid(runif(50), mid = 0.5)
rescale_mid(1)
}
scales/man/trans_new.Rd 0000644 0001762 0000144 00000002757 13641652035 014606 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/trans.r
\name{trans_new}
\alias{trans_new}
\alias{trans}
\alias{is.trans}
\alias{as.trans}
\title{Create a new transformation object}
\usage{
trans_new(
name,
transform,
inverse,
breaks = extended_breaks(),
minor_breaks = regular_minor_breaks(),
format = format_format(),
domain = c(-Inf, Inf)
)
is.trans(x)
as.trans(x)
}
\arguments{
\item{name}{transformation name}
\item{transform}{function, or name of function, that performs the
transformation}
\item{inverse}{function, or name of function, that performs the
inverse of the transformation}
\item{breaks}{default breaks function for this transformation. The breaks
function is applied to the raw data.}
\item{minor_breaks}{default minor breaks function for this transformation.}
\item{format}{default format for this transformation. The format is applied
to breaks generated to the raw data.}
\item{domain}{domain, as numeric vector of length 2, over which
transformation is valued}
}
\description{
A transformation encapsulates a transformation and its inverse, as well
as the information needed to create pleasing breaks and labels. The breaks
function is applied on the transformed range of the range, and it's
expected that the labels function will perform some kind of inverse
transformation on these breaks to give them labels that are meaningful on
the original scale.
}
\seealso{
\Sexpr[results=rd,stage=build]{scales:::seealso_trans()}
}
\keyword{internal}
scales/man/grey_pal.Rd 0000644 0001762 0000144 00000000777 13556361126 014413 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/pal-grey.r
\name{grey_pal}
\alias{grey_pal}
\title{Grey scale palette (discrete)}
\usage{
grey_pal(start = 0.2, end = 0.8)
}
\arguments{
\item{start}{grey value at low end of palette}
\item{end}{grey value at high end of palette}
}
\description{
Grey scale palette (discrete)
}
\examples{
show_col(grey_pal()(25))
show_col(grey_pal(0, 1)(25))
}
\seealso{
\code{\link[=seq_gradient_pal]{seq_gradient_pal()}} for continuous version
}
scales/man/dichromat_pal.Rd 0000644 0001762 0000144 00000001324 13556361126 015404 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/pal-dichromat.r
\name{dichromat_pal}
\alias{dichromat_pal}
\title{Dichromat (colour-blind) palette (discrete)}
\usage{
dichromat_pal(name)
}
\arguments{
\item{name}{Name of colour palette. One of:
\Sexpr[results=rd,stage=build]{scales:::dichromat_schemes()}}
}
\description{
Dichromat (colour-blind) palette (discrete)
}
\examples{
if (requireNamespace("dichromat", quietly = TRUE)) {
show_col(dichromat_pal("BluetoOrange.10")(10))
show_col(dichromat_pal("BluetoOrange.10")(5))
# Can use with gradient_n to create a continous gradient
cols <- dichromat_pal("DarkRedtoBlue.12")(12)
show_col(gradient_n_pal(cols)(seq(0, 1, length.out = 30)))
}
}
scales/man/muted.Rd 0000644 0001762 0000144 00000000664 13556361126 013722 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/colour-manip.r
\name{muted}
\alias{muted}
\title{Mute standard colour}
\usage{
muted(colour, l = 30, c = 70)
}
\arguments{
\item{colour}{character vector of colours to modify}
\item{l}{new luminance}
\item{c}{new chroma}
}
\description{
Mute standard colour
}
\examples{
muted("red")
muted("blue")
show_col(c("red", "blue", muted("red"), muted("blue")))
}
scales/man/format_format.Rd 0000644 0001762 0000144 00000001045 13556361126 015436 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/labels-retired.R
\name{format_format}
\alias{format_format}
\title{Label using \code{format()}}
\usage{
format_format(...)
}
\arguments{
\item{...}{Arguments passed on to \code{\link[=format]{format()}}.}
}
\description{
\Sexpr[results=rd, stage=render]{lifecycle::badge("retired")}
This function is kept for backward compatiblity; you should either use
\code{\link[=label_number]{label_number()}} or \code{\link[=label_date]{label_date()}} instead.
}
\keyword{internal}
scales/man/breaks_extended.Rd 0000644 0001762 0000144 00000001612 13556361126 015725 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/breaks.r
\name{breaks_extended}
\alias{breaks_extended}
\alias{extended_breaks}
\title{Automatic breaks for numeric axes}
\usage{
breaks_extended(n = 5, ...)
}
\arguments{
\item{n}{Desired number of breaks. You may get slightly more or fewer
breaks that requested.}
\item{...}{other arguments passed on to \code{\link[labeling:extended]{labeling::extended()}}}
}
\description{
Uses Wilkinson's extended breaks algorithm as implemented in the
\pkg{labeling} package.
}
\examples{
demo_continuous(c(0, 10))
demo_continuous(c(0, 10), breaks = breaks_extended(3))
demo_continuous(c(0, 10), breaks = breaks_extended(10))
}
\references{
Talbot, J., Lin, S., Hanrahan, P. (2010) An Extension of
Wilkinson's Algorithm for Positioning Tick Labels on Axes, InfoVis
2010 \url{http://vis.stanford.edu/files/2010-TickLabels-InfoVis.pdf}.
}
scales/man/col2hcl.Rd 0000644 0001762 0000144 00000001450 13641652035 014121 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/colour-manip.r
\name{col2hcl}
\alias{col2hcl}
\title{Modify standard R colour in hcl colour space.}
\usage{
col2hcl(colour, h = NULL, c = NULL, l = NULL, alpha = NULL)
}
\arguments{
\item{colour}{character vector of colours to be modified}
\item{h}{Hue, \verb{[0, 360]}}
\item{c}{Chroma, \verb{[0, 100]}}
\item{l}{Luminance, \verb{[0, 100]}}
\item{alpha}{Alpha, \verb{[0, 1]}.}
}
\description{
Transforms rgb to hcl, sets non-missing arguments and then backtransforms
to rgb.
}
\examples{
reds <- rep("red", 6)
show_col(col2hcl(reds, h = seq(0, 180, length = 6)))
show_col(col2hcl(reds, c = seq(0, 80, length = 6)))
show_col(col2hcl(reds, l = seq(0, 100, length = 6)))
show_col(col2hcl(reds, alpha = seq(0, 1, length = 6)))
}
scales/man/train_continuous.Rd 0000644 0001762 0000144 00000000632 13560275211 016174 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/scale-continuous.r
\name{train_continuous}
\alias{train_continuous}
\title{Train (update) a continuous scale}
\usage{
train_continuous(new, existing = NULL)
}
\arguments{
\item{new}{New data to add to scale}
\item{existing}{Optional existing scale to update}
}
\description{
Strips attributes and always returns a numeric vector
}
scales/man/shape_pal.Rd 0000644 0001762 0000144 00000000444 13556361126 014534 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/pal-shape.r
\name{shape_pal}
\alias{shape_pal}
\title{Shape palette (discrete)}
\usage{
shape_pal(solid = TRUE)
}
\arguments{
\item{solid}{should shapes be solid or not?}
}
\description{
Shape palette (discrete)
}
scales/man/hms_trans.Rd 0000644 0001762 0000144 00000000607 13556361126 014577 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/trans-date.r
\name{hms_trans}
\alias{hms_trans}
\title{Transformation for times (class hms)}
\usage{
hms_trans()
}
\description{
Transformation for times (class hms)
}
\examples{
if (require("hms")) {
hms <- round(runif(10) * 86400)
t <- hms_trans()
t$transform(hms)
t$inverse(t$transform(hms))
t$breaks(hms)
}
}
scales/man/asn_trans.Rd 0000644 0001762 0000144 00000000520 13556361126 014563 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/trans-numeric.r
\name{asn_trans}
\alias{asn_trans}
\title{Arc-sin square root transformation}
\usage{
asn_trans()
}
\description{
This is the variance stabilising transformation for the binomial
distribution.
}
\examples{
plot(asn_trans(), xlim = c(0, 1))
}
scales/man/expand_range.Rd 0000644 0001762 0000144 00000001022 13556361126 015224 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/bounds.r
\name{expand_range}
\alias{expand_range}
\title{Expand a range with a multiplicative or additive constant}
\usage{
expand_range(range, mul = 0, add = 0, zero_width = 1)
}
\arguments{
\item{range}{range of data, numeric vector of length 2}
\item{mul}{multiplicative constant}
\item{add}{additive constant}
\item{zero_width}{distance to use if range has zero width}
}
\description{
Expand a range with a multiplicative or additive constant
}
scales/man/figures/ 0000755 0001762 0000144 00000000000 13656262515 013756 5 ustar ligges users scales/man/figures/README-labels-1.png 0000644 0001762 0000144 00000155774 13655055705 017042 0 ustar ligges users ‰PNG
IHDR ŕ l< ! iCCPkCGColorSpaceGenericRGB 8ŤŤU]hU>»sg#$ÎSl4…t¨?
%
“V4ˇ´şÝÝ6n–I6Ú"čdöîÎÉÎ83»ýˇOEP|1ę›Äż·€ (őŰ>´/•
%ÚÔ (>´řP苦ë™;3™iş±Ţeî|óťďž{îągď蹪X–‘š®-2âs‡Ź=+„‡ ˇWQ+]©L6Owµ[ßCÂ{_ŮŐÝţź·F qbłć¨Źđ§UËvzú‘?ęZöbč·1@Ä/z¸ác×Ăs>~Ťifä,âÓUSj—ŹĚĹřFű1°Ö_ MjëŞčĺ˘b›uÝ ±pďaţźmÁh…ómçϙź>„ďa\ű+5%çáQÄKŞ’źFüâkm}¶ŕŰ–›‘?ÜŢšŻ¦ďD\¬ŰŞľź¤µŠ!~ç„6ó,â-Ď7çĘSÁŘ«Ş“ĹśÁvÄ·5Zňň;Ŕ‰ş[šńÇrűmSžňçĺę5šË{yDüúĽyHö}rź9íé|čó„–-üĄ—”ġFAöçâţ±ÜJjĺI.’Ł[/ă]m¦čĎK7ÔKëúR ˙Dł‹r€ŻY«QŚŤOÚ-ąęëůQĹÎ|ź|…6«ľ
ł (0‡˝
MXd(@ßŘh©2Š_ˇfçŔ<ň:´™ÍÁľÂ”ţČČ_ů¸Î´*d‡>‚˛üެÓeń«…\c?~,7?& ŮĎ^2Iö‘q2"yŠ