Package: scales 1.3.0.9000

scales: Scale Functions for Visualization
Graphical scales map data to aesthetics, and provide methods for automatically determining breaks and labels for axes and legends.
Authors:
scales_1.3.0.9000.tar.gz
scales_1.3.0.9000.zip(r-4.5)scales_1.3.0.9000.zip(r-4.4)scales_1.3.0.9000.zip(r-4.3)
scales_1.3.0.9000.tgz(r-4.5-any)scales_1.3.0.9000.tgz(r-4.4-any)scales_1.3.0.9000.tgz(r-4.3-any)
scales_1.3.0.9000.tar.gz(r-4.5-noble)scales_1.3.0.9000.tar.gz(r-4.4-noble)
scales_1.3.0.9000.tgz(r-4.4-emscripten)scales_1.3.0.9000.tgz(r-4.3-emscripten)
scales.pdf |scales.html✨
scales/json (API)
NEWS
# Install 'scales' in R: |
install.packages('scales', repos = c('https://r-lib.r-universe.dev', 'https://cloud.r-project.org')) |
Bug tracker:https://github.com/r-lib/scales/issues
Pkgdown site:https://scales.r-lib.org
On CRAN:scales-1.3.0(2023-11-28)
Last updated 4 months agofrom:ee03582857. Checks:8 OK. Indexed: yes.
Target | Result | Latest binary |
---|---|---|
Doc / Vignettes | OK | Jan 29 2025 |
R-4.5-win | OK | Feb 19 2025 |
R-4.5-mac | OK | Jan 29 2025 |
R-4.5-linux | OK | Jan 29 2025 |
R-4.4-win | OK | Jan 29 2025 |
R-4.4-mac | OK | Jan 29 2025 |
R-4.3-win | OK | Jan 29 2025 |
R-4.3-mac | OK | Jan 29 2025 |
Exports:abs_areaalphaarea_palas_continuous_palas_discrete_palas.transas.transformasinh_transasn_transatanh_transboxcox_transbreaks_expbreaks_extendedbreaks_logbreaks_prettybreaks_timespanbreaks_widthbrewer_palcbreakscensorcol_bincol_darkercol_factorcol_lightercol_mixcol_numericcol_quantilecol_saturatecol_shiftcol2hclcolour_rampcommacomma_formatcompose_labelcompose_transContinuousRangecscalecut_long_scalecut_short_scalecut_sicut_time_scaledate_breaksdate_formatdate_transdemo_continuousdemo_datetimedemo_discretedemo_log10demo_timedemo_timespandichromat_paldiscardDiscreteRangediv_gradient_paldollardollar_formatdscaleexp_transexpand_rangeextended_breaksformat_formatformat_logfullseqget_palettegradient_n_palgrey_palhms_transhue_palidentity_palidentity_transis_colour_palis_continuous_palis_discrete_palis_numeric_palis_palis.transis.transformlabel_byteslabel_commalabel_currencylabel_datelabel_date_shortlabel_dictionarylabel_dollarlabel_gluelabel_loglabel_mathlabel_numberlabel_number_autolabel_number_silabel_ordinallabel_parselabel_percentlabel_pvaluelabel_scientificlabel_timelabel_timespanlabel_wraplinetype_pallog_breakslog_translog10_translog1p_translog2_translogit_transmanual_palmath_formatminor_breaks_logminor_breaks_nminor_breaks_widthmodulus_transmutednew_continuous_palettenew_discrete_palettenew_transformnumbernumber_bytesnumber_bytes_formatnumber_formatnumber_optionsoob_censoroob_censor_anyoob_discardoob_keepoob_squishoob_squish_anyoob_squish_infiniteordinalordinal_englishordinal_formatordinal_frenchordinal_spanishpal_areapal_brewerpal_dichromatpal_div_gradientpal_gradient_npal_greypal_huepal_identitypal_linetypepal_manualpal_rescalepal_seq_gradientpal_shapepal_viridispalette_na_safepalette_namespalette_nlevelspalette_typeparse_formatpercentpercent_formatpretty_breaksprobability_transprobit_transpseudo_log_transpvaluepvalue_formatRangereciprocal_transregular_minor_breaksrescalerescale_maxrescale_midrescale_nonerescale_palreset_palettesreverse_transscientificscientific_formatseq_gradient_palset_paletteshape_palshow_colsqrt_transsquishsquish_infinitetime_formattime_transtimespan_transtrain_continuoustrain_discretetrans_breakstrans_formattrans_newtrans_rangetransform_asinhtransform_asntransform_atanhtransform_boxcoxtransform_composetransform_datetransform_exptransform_hmstransform_identitytransform_logtransform_log10transform_log1ptransform_log2transform_logittransform_modulustransform_probabilitytransform_probittransform_pseudo_logtransform_reciprocaltransform_reversetransform_sqrttransform_timetransform_timespantransform_yjtrim_to_domainunit_formatviridis_palwrap_formatyj_transzero_range
Dependencies:clifarvergluelabelinglifecycleR6RColorBrewerrlangviridisLite
Citation
To cite package ‘scales’ in publications use:
Wickham H, Pedersen T, Seidel D (2025). scales: Scale Functions for Visualization. R package version 1.3.0.9000, , https://github.com/r-lib/scales.
Corresponding BibTeX entry:
@Manual{, title = {scales: Scale Functions for Visualization}, author = {Hadley Wickham and Thomas Lin Pedersen and Dana Seidel}, year = {2025}, note = {R package version 1.3.0.9000, }, url = {https://github.com/r-lib/scales}, }
Readme and manuals
scales

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, and gives you tools to override the default breaks, labels, transformations and palettes.
Installation
# 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("pak")
# pak::pak("r-lib/scales")
install.packages("scales", repos = c('https://r-lib.r-universe.dev', 'https://cloud.r-project.org'))
Usage
Breaks and labels
The most common use of the scales package is 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.
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(scale_cut = scales::cut_short_scale())
)

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 jog 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.
#| sepal length and sepal width in the Iris dataset. The points are coloured
#| according to species and the `scales::pal_brewer()` are used to provide the
#| colours.
library(scales)
# pull a list of colours from any palette
pal_viridis()(4)
#> [1] "#440154FF" "#31688EFF" "#35B779FF" "#FDE725FF"
# use in combination with baseR `palette()` to set new defaults
palette(pal_brewer(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.
# use new_transform to build a new transformation
transform_logp3 <- new_transform(
name = "logp",
transform = 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 = transform_logp3)

Help Manual
Help page | Topics |
---|---|
Modify colour transparency | alpha |
Breaks for exponentially transformed data | breaks_exp |
Automatic breaks for numeric axes | breaks_extended extended_breaks |
Breaks for log axes | breaks_log log_breaks |
Pretty breaks for date/times | breaks_pretty |
Breaks for timespan data | breaks_timespan |
Equally spaced breaks | breaks_width |
Mix colours | col_mix |
Colour mapping | col_bin col_factor col_numeric col_quantile |
Modify standard R colour in hcl colour space. | col2hcl |
Colour manipulation | colour_manip col_darker col_lighter col_saturate col_shift |
Fast colour interpolation | colour_ramp |
Compose two or more label formatters together | compose_label |
Continuous scale | cscale |
Discrete scale | dscale |
Expand a range with a multiplicative or additive constant | expand_range |
Known palettes | get_palette palette_names reset_palettes set_palette |
Label bytes (1 kB, 2 MB, etc) | label_bytes |
Label currencies ($100, €2.50, etc) | label_currency |
Label date/times | label_date label_date_short label_time label_timespan |
Labels from lookup tables | label_dictionary |
Interpolated labels | label_glue |
Label numbers in log format (10^3, 10^6, etc) | format_log label_log |
Label numbers in decimal format (e.g. 0.12, 1,234) | label_comma label_number |
Label numbers, avoiding scientific notation where possible | label_number_auto |
Label ordinal numbers (1st, 2nd, 3rd, etc) | label_ordinal ordinal_english ordinal_french ordinal_spanish |
Label with mathematical annotations | label_math label_parse |
Label percentages (2.5%, 50%, etc) | label_percent |
Label p-values (e.g. <0.001, 0.25, p >= 0.99) | label_pvalue |
Label numbers with scientific notation (e.g. 1e05, 1.5e-02) | label_scientific |
Label strings by wrapping across multiple lines | label_wrap |
Minor breaks for log-10 axes | minor_breaks_log |
Minor breaks | minor_breaks_n minor_breaks_width |
Mute standard colour | muted |
Constructors for palettes | as_continuous_pal as_discrete_pal is_colour_pal is_continuous_pal is_discrete_pal is_numeric_pal is_pal new_continuous_palette new_discrete_palette palette_na_safe palette_nlevels palette_type |
Number options | number_options |
Out of bounds handling | censor discard oob oob_censor oob_censor_any oob_discard oob_keep oob_squish oob_squish_any oob_squish_infinite squish squish_infinite |
Area palettes (continuous) | abs_area area_pal pal_area |
Colour Brewer palette (discrete) | brewer_pal pal_brewer |
Dichromat (colour-blind) palette (discrete) | dichromat_pal pal_dichromat |
Diverging colour gradient (continuous). | div_gradient_pal pal_div_gradient |
Arbitrary colour gradient palette (continuous) | gradient_n_pal pal_gradient_n |
Grey scale palette (discrete) | grey_pal pal_grey |
Hue palette (discrete) | hue_pal pal_hue |
Identity palette | identity_pal pal_identity |
Line type palette (discrete) | linetype_pal pal_linetype |
Manual palette (discrete) | manual_pal pal_manual |
Rescale palette (continuous) | pal_rescale rescale_pal |
Sequential colour gradient palette (continuous) | pal_seq_gradient seq_gradient_pal |
Shape palette (discrete) | pal_shape shape_pal |
Viridis palette | pal_viridis viridis_pal |
Mutable ranges | ContinuousRange DiscreteRange Range |
Rescale continuous vector to have specified minimum and maximum | rescale rescale.AsIs rescale.Date rescale.difftime rescale.dist rescale.integer64 rescale.logical rescale.numeric rescale.POSIXt |
Rescale numeric vector to have specified maximum | rescale_max |
Rescale vector to have specified minimum, midpoint, and maximum | rescale_mid rescale_mid.AsIs rescale_mid.Date rescale_mid.dist rescale_mid.integer64 rescale_mid.logical rescale_mid.numeric rescale_mid.POSIXt |
Don't perform rescaling | rescale_none |
Train (update) a continuous scale | train_continuous |
Train (update) a discrete scale | train_discrete |
Inverse Hyperbolic Sine transformation | asinh_trans transform_asinh |
Arc-sin square root transformation | asn_trans transform_asn |
Arc-tangent transformation | atanh_trans transform_atanh |
Box-Cox & modulus transformations | boxcox_trans modulus_trans transform_boxcox transform_modulus |
Compose two or more transformations together | compose_trans transform_compose |
Transformation for dates (class Date) | date_trans transform_date |
Exponential transformation (inverse of log transformation) | exp_trans transform_exp |
Identity transformation (do nothing) | identity_trans transform_identity |
Log transformations | log10_trans log1p_trans log2_trans log_trans pseudo_log_trans transform_log transform_log10 transform_log1p transform_log2 transform_pseudo_log |
Probability transformation | logit_trans probability_trans probit_trans transform_logit transform_probability transform_probit |
Reciprocal transformation | reciprocal_trans transform_reciprocal |
Reverse transformation | reverse_trans transform_reverse |
Square-root transformation | sqrt_trans transform_sqrt |
Transformation for date-times (class POSIXt) | time_trans transform_time |
Transformation for times (class hms) | hms_trans timespan_trans transform_hms transform_timespan |
Yeo-Johnson transformation | transform_yj yj_trans |
Determine if range of vector is close to zero, with a specified tolerance | zero_range |