hadley/ggplot2 — pull request #473 by wch (2012-04-06 19:47:08+00:00)
Title: Fix for polar spacing with x (fix #282)

This fixes #282.

When using bars with `width` < 1, the spacing is uneven, as demonstrated in #282:

```R
dat <- data.frame(x=LETTERS[1:3], y=4)

# Bad
# A and C boxes touch - angle AC is smaller than AB and BC
ggplot(dat, aes(x=x, y=y)) + geom_bar() + coord_polar()
```

A longhand manual solution is to use `expand=TRUE` and set the `expand` values in both the x and y scales. The `expand` values that are appropriate for a circular graph are different from those for a rectangular graph. However, this is really verbose:

```R
# Good
# This removes the space in the middle
ggplot(dat, aes(x=x, y=y)) + geom_bar() +
coord_polar(expand=T) +
scale_x_discrete(expand=c(0, .5)) + # equal theta spacing
scale_y_continuous(expand=c(0, 0)) # don't leave a hole in the middle
```

As far as I can tell, there's no reason to use `expand` values that are different from these ones, in a polar graph. You don't want your theta/x to be spaced unevenly, and you don't want a hole in the middle. If you really want to change these things, you can set `xlim` and `ylim`.

This pull request also overrides `expand` values for racetrack plots (where `theta="y"`). In the existing code, if you use `expand=TRUE` with a racetrack plot, it doesn't form a full circle, but I overrode it close the circle. Again, if you want to override these values, you should be able to set `xlim` and `ylim`.

Thoughts?