concept scale in category R

appears as: scale, scales
Beyond Spreadsheets with R

This is an excerpt from Manning's book Beyond Spreadsheets with R.

Measurements are composed of two parts: a value and a scale. We may tend to abbreviate this when we talk (“I was driving at 60”), but this only makes sense if we assume everyone is familiar with the units (was that kilometers per hour or miles per hour?). You may store population counts on the scale of “millions of people,” but the value you use may be only 318.9.

Figure 9.40 You can extend the scale to a not-yet-present fourth level.

ggplot_limits-1.png

This usage of limits differs somewhat from the usage in scale_x_continuous(). The help file for scale_x_discrete() notes that the meaning of the argument limits is “A character vector that defines possible values of the scale and their order.” That’s what you've provided — a character vector (due to as.character()) of the values to be used on the x-axis, and their order. These are c("2", "4", "6", "8").

Some of the groups don’t have many values, so it’s sometimes useful to be able to change the scale. You need to change it differently for each facet, though, so that option is built right in as the scales argument, which takes a "free" value to make the scaling independent for each facet (shown in figure 9.49):

ggplot(mtcars, aes(mpg, disp, col = factor(carb))) +
  geom_point() +
  facet_wrap(~ carb, scales = "free")

Figure 9.49 Using scales = "free" means the scale in each facet panel is independent.

ggplot_facetfree-1.png

Figure 9.50 You can keep only one axis fixed using scales = "free_x".

ggplot_facetfreex-1.png