5.2 Scales

5.2.1 Logarithmic

5.2.2 Expand limits

Specify the value you want to be included:

Or two:

By default, ggplot() adds some padding around the included area (see how the scale doesn’t start from 0, but slightly before). You can remove this padding with the expand option:

We are now using a new library - patchwork - to print all 4 plots together. Its syntax is very simple - it allows us to add ggplot objects together. (Trying to do p1 + p2 without loading the patchwork package will not work, R will say “Error: Don’t know how to add p2 to a plot”.)

5.2.4 Exercise

How is this one different to the previous?

Answer: the first one zooms in, still retaining information about the excluded points when calculating the linear regression lines. The second one removes the data (as the warnings say), calculating the linear regression lines only for the visible points.

## Warning: Removed 114 rows containing non-finite values (stat_smooth).
## Warning: Removed 114 rows containing missing values (geom_point).

5.2.6 Swap the axes