Learn R Programming

ggplot2 (version 4.0.4)

Scale: Scales

Description

All scale_*() functions (like scale_fill_continuous()) return a Scale* object. The main purpose of these objects is to translate data values to aesthetic values and populating breaks and labels.

Arguments

Details

All scale_* functions like scale_x_continuous() return a Scale* object like ScaleContinuous. Each of the Scale* objects is a ggproto() object descended from the top-level Scale.

Scales generally need to track three types of spaces:

  1. Data space. These are values as they are evaluated from the plot or layer mapping, prior to any transformation.

  2. Transformed space. This is the space after original data has been transformed. Effectively, scales internally operate in transformed space in that ranges and breaks get passed around in this space. Discrete scales don't do transformations, so for these scales, transformed space is the same as untransformed space.

  3. Aesthetic space. Graphic values that are mapped from the transformed space. This is dependent on the palette field for most scales and on the rescaler field for continuous position scales.

The user is expected to give any vector-based minor_breaks, breaks or limits in data space. When breaks, limits or labels is a function, its input is expected to be in data space.

Before you attempt to create a new Scale* class of your own, it is recommended to think through whether your aims cannot be implemented with one of the existing classes. Making a wrapper for the continuous_scale(), discrete_scale() and binned_scale() should cover many cases, and should be considered prior to commiting to build a Scale* extension.

For example, if you aim to develop a scale for a new data type, it should generally be possible to create a new transformation instead. One reason to implement your own Scale* class is to accommodate a data type does not lend itself for continuous or discrete range training.

In such case, you can override the following:

  • The range field.

  • The transform, train and map methods.

  • The get_limits(), get_breaks() and get_labels() methods.

Examples

Run this code
# TODO: find easy to digest example
NULL

Run the code above in your browser using DataLab