Scales

Scales take care of the mapping of aesthetic attributes to the data. When the data is assigned to aesthetic mapping, the scales map the data to the corresponding aesthetic attribute, and this is done via a specific function depending on the scale applied. The inverse of this function is then used to map back the elements from the aesthetic to the actual value of the data. This process is used to create the axis, to represent the x-y position of the elements on the plot, or to create the legends that represent the mapping of other aesthetic attributes.

If, for instance, we consider the assignment of data to a color scale. First, the data is assigned to a color by mapping the value of the data to colors within the range defined by the scale, and then the inverse of the scale defines the total range of colors used in the mapping, which will be used to draw the legend of the graph.

Within a plot, each aesthetic assignment has a different scale, and each aesthetic attribute has a default scale assigned. After the scale is assigned to an aesthetic, the same scale is applied to that specific aesthetic on all the data in the plot in order to guarantee consistent mapping.

In the following Figure 3.4, you will find some examples of scales depicted. As illustrated, scales will appear slightly different if they apply to scatterplots, with point geometry or if they apply to the filling of histograms, for instance. In ggplot2, you have access to color scales in the continuous range, which can be used to map continuous variables. Finally, we also have the possibility of mapping variables to the size or shape of the symbols used in the plot. We will cover the topic of scales in more detail in Chapter 5, Controlling Plot Details, so for now, it is only important that you have an idea of the different possibilities available in ggplot2.

Scales

Figure 3.4: These are a few examples of typical scales

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset