Scales control the mapping between variables and aesthetic properties, and so we need one scale for each aesthetic property used in a layer. Scales are common across layers to ensure a consistent mapping from data to aesthetics. The mapping (see aes) controls which variables are mapped to which aesthetic properties, and the scales control the details of that mapping.
A scale is a function, and its inverse, along with a set of parameters. For example, the colour gradient scale maps a segment of the real line to a path through a colour space. The parameters of the function define whether the path is linear or curved, which colour space to use (eg. LUV or RGB), and the starting and ending points of the line (specified as colours). The inverse function is used to draw a legend so that you can read the values off of the graph.
In general, the inverse function will be displayed as a guide. Guides are either axes (for position scales) or legends (for everything else). Axis guides are drawn in conjunction with the coordinate system.
Scales typically map from a single variable to a single aesthetic, however, there are exceptions. For example, we can map one variable to hue and another to saturation, to create a single aesthetic, colour. We can also create redundant mappings, mapping the same variable to multiple aesthetics. This is most useful when producing a graphic for both colour and black and white display. Generally, mapping a single variable to a single aesthetic creates the most readily perceivable mapping.
Scaling is broken into three phases:
Statistics are computed after transforming
The scale also control the inverse mapping from aesthetics to data. This mapping is displayed as axes for position scales, and legends for all other scales. Currently, there are few controls over these guides, apart from being able to set the breakpoints (with the breaks
argument) and the labels that appear at those breakpoints (with the labels
argument).
The first argument for all scales is the name
that will appear in the legend or axis. If you do not specify this, it will default to the expression which appeared in the first mapping.
Most continuous scales have limit
and to
arguments. The limit argument control the ranges of data that will appear on the scale (cf. xlim and ylim in qplot), and is mostly used for position scales. The to
argument controls the range the aesthetics are mapped into, and is mostly used for non-position scales, eg. scale_size.