Session Ready
Exercise

Annotating logarithmic scales

We have seen how the scales argument can be used to control various aspects of how the coordinate axes are computed and annotated. A common use of the scales argument is to explicitly specify tick mark locations using the at sub-component, and optionally the associated text labels using the labels sub-component.

The goal of this exercise is to use this feature to provide custom labels in a logarithmic scale.

Instructions
100 XP

The USMortality data has been pre-loaded.

Fill in the sample code so that

  • Assign the variable x_ticks_at, equal to powers of 2 (i.e., 2^3, 2^4, ..., 2^8). Be careful of operator precedence.

  • Complete the plotting code.

    • The tick marks on the x-axis appear at x_ticks_at.

    • The corresponding labels are the actual numerical values; i.e, 2^3 should have label 8, 2^4 should have label 16, and so on. Note: If you pass a numeric vector to labels, R will automatically coerce it into a character vector.