8.15 Adding Ticks for a Logarithmic Axis

8.15.1 Problem

You want to add tick marks with diminishing spacing for a logarithmic axis.

8.15.3 Discussion

The tick marks created by annotation_logticks() are actually geoms inside the plotting area. There is a long tick mark at each power of 10, and a mid-length tick mark at each 5.

To get the colors of the tick marks and the grid lines to match up a bit better, you can use theme_bw().

By default, the minor grid lines appear visually halfway between the major grid lines, but this is not the same place as the “5” tick marks on a logarithmic scale. To get them to be the same, we can supply a function for the scales minor_breaks.

We’ll define breaks_5log10(), which returns 5 times powers of 10 that encompass the values passed to it.

Then we’ll use that function for the minor breaks (Figure 8.32):

Log axes with ticks at each 5, and fixed coordinate ratio

Figure 8.32: Log axes with ticks at each 5, and fixed coordinate ratio