scales v0.4.1


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

Last month downloads


LinkingTo Rcpp
License MIT + file LICENSE
LazyLoad yes
RoxygenNote 5.0.1
NeedsCompilation yes
Packaged 2016-11-08 19:11:18 UTC; hadley
Repository CRAN
Date/Publication 2016-11-09 18:28:56

Include our badge in your README