scales v0.4.0


Monthly downloads



by Hadley Wickham

Scale Functions for Visualization

Graphical scales map data to aesthetics, and provide methods for automatically determining breaks and labels for axes and legends.



Build Status Coverage Status CRAN_Status_Badge

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 idea of the scales package is to implement scales in a way that is graphics system agnostic, so that everyone can benefit by pooling knowledge and resources about this tricky topic.


The scales package is made up of the following interdependent components

  • Palettes, pal for short, describe the useful palettes of aesthetics.

  • Transformations, trans for short, describe common scale transformations, their inverses, and ways of generating breaks and labels.

  • Bounds: various ways of rescaling the data

  • Scaling functions: pull together palettes, bounding functions and transformations to provide a complete pathway from raw data to perceptual properties

  • Mutable ranges: in many graphics pathways, scale ranges can not be computed in a single pass, but must be computed over multiple groups or multiple panels. The mutable ranges (implemented with R's new reference based class) provide a thin layer of mutability to make this task easier.


  • Breaks and formats: ways of computing how tick marks/legend keys should be distributed across the data range, as well as how to convert those numeric positions into reader-friendly labels

Functions in scales

Name Description
date_breaks Regularly spaced dates.
cscale Continuous scale.
div_gradient_pal Diverging colour gradient (continous).
date_trans Transformation for dates (class Date).
Range-class Mutable ranges.
abs_area Point area palette (continuous), with area proportional to value.
rescale_pal Rescale palette (continuous).
col_numeric Color mapping
muted Mute standard colour.
dollar_format Currency formatter: round to nearest cent and display dollar sign.
seq_gradient_pal Sequential colour gradient palette (continous).
parse_format Parse a text label to produce expressions for plotmath.
manual_pal Manual palette (manual).
fullseq Generate sequence of fixed size intervals covering range.
rescale Rescale numeric vector to have specified minimum and maximum.
discard Discard any values outside of range.
col2hcl Modify standard R colour in hcl colour space.
brewer_pal Color Brewer palette (discrete).
shape_pal Shape palette (discrete).
identity_trans Identity transformation (do nothing).
colour_ramp Fast color interpolation
package-scales Generic plot scaling methods
train_continuous Train (update) a continuous scale
extended_breaks Extended breaks. Uses Wilkinson's extended breaks algorithm as implemented in the labeling package.
scientific_format Scientific formatter.
train_discrete Train (update) a discrete scale
ordinal_format Ordinal formatter: add ordinal suffixes (-st, -nd, -rd, -th) to numbers.
pretty_breaks Pretty breaks. Uses default R break algorithm as implemented in pretty.
expand_range Expand a range with a multiplicative or additive constant.
rescale_mid Rescale numeric vector to have specified minimum, midpoint, and maximum.
comma_format Comma formatter: format number with commas separating thousands.
log_breaks Log breaks (integer breaks on log-transformed scales).
math_format Add arbitrary expression to a label. The symbol that will be replace by the label value is .x.
rescale_max Rescale numeric vector to have specified maximum.
rescale_none Don't peform rescaling
as.trans Convert character string to transformer.
unit_format Add units to the labels
boxcox_trans Box-Cox power transformation.
area_pal Point area palette (continuous).
hue_pal Hue palette (discrete).
exp_trans Exponential transformation (inverse of log transformation).
percent_format Percent formatter: multiply by one hundred and display percent sign.
cbreaks Compute breaks for continuous scale.
zero_range Determine if range of vector is close to zero, with a specified tolerance
grey_pal Grey scale palette (discrete).
gradient_n_pal Arbitrary colour gradient palette (continous).
trans_breaks Pretty breaks on transformed scale.
show_col Show colours.
sqrt_trans Square-root transformation.
log_trans Log transformation.
date_format Formatted dates.
linetype_pal Line type palette (discrete).
time_trans Transformation for times (class POSIXt).
probability_trans Probability transformation.
trans_format Format labels after transformation.
squish Squish values into range.
log1p_trans Log plus one transformation.
trans_range Compute range of transformed values.
squish_infinite Squish infinite values to range.
asn_trans Arc-sin square root transformation.
dscale Discrete scale.
identity_pal Identity palette.
reciprocal_trans Reciprocal transformation.
wrap_format Wrap text to a specified width, adding newlines for spaces if text exceeds the width
censor Censor any values outside of range.
dichromat_pal Dichromat (colour-blind) palette (discrete).
atanh_trans Arc-tangent transformation.
format_format Format with using any arguments to format.
trans_new Create a new transformation object.
reverse_trans Reverse transformation.
alpha Modify colour transparency. Vectorised in both colour and alpha.
No Results!

Last month downloads


LinkingTo Rcpp
License MIT + file LICENSE
LazyLoad yes
RoxygenNote 5.0.1
NeedsCompilation yes
Packaged 2016-02-26 13:10:16 UTC; hadley
Repository CRAN
Date/Publication 2016-02-26 15:45:07

Include our badge in your README