12.1 Size
The size aesthetic is typically used to scale points and text. The default scale for size aesthetics is scale_size() in which a linear increase in the variable is mapped onto a linear increase in the area (not the radius) of the geom.
There are several size scales:
scale_size_area() and scale_size_binned_area() are versions of scale_size() and scale_size_binned() that ensure that a value of 0 maps to an area of 0.
scale_radius() maps the data value to the radius rather than to the area (Section 12.1.1).
scale_size_binned() is a size scale that behaves like scale_size() but maps continuous values onto discrete size categories, analogous to the binned position and colour scales discussed in Sections 10.4 and 11.4 respectively. Legends associated with this scale are discussed in Section 12.1.2.
scale_size_date() and scale_size_datetime() are designed to handle date data, analogous to the date scales discussed in Section 10.2.
12.1.1 Radius size scales
There are situations where area scaling is undesirable, and for such situations scale_radius() may be more appropriate. For example, consider a data set containing astronomical data that includes the radius of different planets:
## name type position radius orbit
## 1 Mercury Inner 1 2440 57900000
## 2 Venus Inner 2 6052 108200000
## 3 Earth Inner 3 6378 149600000
## 4 Mars Inner 4 3390 227900000
## 5 Jupiter Outer 5 71400 778300000
## 6 Saturn Outer 6 60330 1427000000
## 7 Uranus Outer 7 25559 2871000000
## 8 Neptune Outer 8 24764 4497100000
12.1.2 Binned size scales
Binned size scales work similarly to binned scales for colour and position aesthetics (Sections 11.4 and 10.4) with the exception of how legends are displayed. The default legend for a binned size scale, and all binned scales except position and colour aesthetics, is governed by guide_bins(). For instance, in the mpg data we could use scale_size_binned() to create a binned version of the continuous variable hwy:
Unlike guide_legend(), the guide created for a binned scale by guide_bins() does not organize the individual keys into a table. Instead they are arranged in a column (or row) along a single vertical (or horizontal) axis, which by default is displayed with its own axis. The important arguments to guide_bins() are listed below:
- axis indicates whether the axis should be drawn (default is TRUE)
- direction is a character string specifying the direction of the guide, either “vertical” (the default) or “horizontal”
- show.limits specifies whether tick marks are shown at the ends of the guide axis (default is FALSE)
- axis.colour, axis.linewidth and axis.arrow are used to control the guide axis that is displayed alongside the legend keys
- keywidth, keyheight, reverse and override.aes have the same behavior for guide_bins() as they do for guide_legend() (see Section 11.3.6)