hadley/ggplot2 — pull request #883 by krlmlr (2013-12-10 01:00:59+00:00)
Title: Fix vertical justification for rotated text

The computation for `x` (or `y`) values based on `vjust` values does not work correctly for all cases. I have shown an example before and after applying this change.

# Before

Everything looks good by default

```r
library(ggplot2)
```

```
## Loading required package: methods
```

```r
library(grid)

(p <- qplot(diamonds$cut, binwidth=0.5) + theme_bw(24) +
theme(axis.text.x=element_text(vjust=0.5)))
showViewport()
```

![plot of chunk unnamed-chunk-2](http://i.imgur.com/wJvs0Zw.png)

Now play with the justification:

```r
(p0 <- p + theme(axis.title=element_text(vjust=0)))
showViewport()
```

![plot of chunk unnamed-chunk-3](http://i.imgur.com/ohnnAKt.png)

And the other extreme:

```r
(p1 <- p + theme(axis.title=element_text(vjust=1)))
showViewport()
```

![plot of chunk unnamed-chunk-4](http://i.imgur.com/GU9x5al.png)

Top-down:

```r
p0 + theme(axis.title.x=element_text(angle=180), axis.title.y=element_text(angle=270))
showViewport()
```

![plot of chunk unnamed-chunk-5](http://i.imgur.com/DkidGOH.png)

Top-down, `vjust==1`:

```r
p1 + theme(axis.title.x=element_text(angle=180), axis.title.y=element_text(angle=270))
showViewport()
```

![plot of chunk unnamed-chunk-6](http://i.imgur.com/4zvJ5q3.png)

This is inconsistent. Changing the justification by 1 should move the text
by "1 lineheight" in both cases.

# After

Everything looks good by default

```r
library(ggplot2)
```

```
## Loading required package: methods
```

```r
library(grid)

(p <- qplot(diamonds$cut, binwidth=0.5) + theme_bw(24) +
theme(axis.text.x=element_text(vjust=0.5)))
showViewport()
```

![plot of chunk unnamed-chunk-2](http://i.imgur.com/dN2C9qS.png)

Now play with the justification:

```r
(p0 <- p + theme(axis.title=element_text(vjust=0)))
showViewport()
```

![plot of chunk unnamed-chunk-3](http://i.imgur.com/1iy0nOP.png)

And the other extreme:

```r
(p1 <- p + theme(axis.title=element_text(vjust=1)))
showViewport()
```

![plot of chunk unnamed-chunk-4](http://i.imgur.com/q1rmbyL.png)

Top-down:

```r
p0 + theme(axis.title.x=element_text(angle=180), axis.title.y=element_text(angle=270))
showViewport()
```

![plot of chunk unnamed-chunk-5](http://i.imgur.com/5ota9WS.png)

Top-down, `vjust==1`:

```r
p1 + theme(axis.title.x=element_text(angle=180), axis.title.y=element_text(angle=270))
showViewport()
```

![plot of chunk unnamed-chunk-6](http://i.imgur.com/1uDspyf.png)