The document is pretty straightforward. If you install limitsmanually, it will be more clear. I will give some examples to show how this works:
the first argument gives an extension equal to its multiplication by the limit range;
ggplot(mpg, aes(displ, hwy)) +
geom_point() +
scale_x_continuous(limits = c(1, 7), expand = c(0.5, 0))
the second gives an absolute extension added to both ends of the axis:
ggplot(mpg, aes(displ, hwy)) +
geom_point() +
scale_x_continuous(limits = c(1, 7), expand = c(0.5, 2))
Finally, the same extension applies to both ends of the axis.
2019-01-23: from @ C.Liu's answer, I found out what expand_scalecan be used to achieve different extensions of the ends of two axes. See C.liu's Answer for details.
source
share