hadley/ggplot2 — pull request #969 by lionelgit (2014-06-01 11:23:57+00:00)
Title: Coord expand

The difference between setting the limits through a coordinate system or via a scale is central to ggplot but the two procedures are not consistent with each other. Compared to scales, the coord functions lack an expand argument. More importantly, they do not apply the default expansion and the same plot will look different in function of which method was used to set limits.

This pull request implements `xexpand` and `yexpand` arguments for coord functions, with the same default expansion as for the scales.

Since setting the limits through coord is symmetric to setting the limits with scales, it should happen in the same place in the code. Furthermore, this allows to know if the scale is continuous or discrete thanks to the scale object being passed along. To make this possible, I changed the coord object to reflect the scale object structure. Coord objects now contains two lists named `x` and `y`, each containing `expand` and limits. In order to make the difference between passing the whole coord object and passing the x or y component, I added a dot to `coord`. When a function receives a `.coord`, we know it is the x or y component of a coord object.

One difficulty that I encountered while checking that everything was ok, is that coord_polar does not have the x and y components. And it needs special treatment for the default expansion, which depends on theta being equal to "x" or "y". My solution was to add x and y objects, containing theta, with class set to "polar" so that `coord_expand_defaults` dispatches correctly the .coord object to `coord_expand_defaults.polar`.