hadley/ggplot2 — pull request #657 by wch (2012-09-05 08:39:32+00:00)
Title: train_position: combine data with rbind.fill before training scales

This is a potential fix for #577.

Instead of training the scales on each layer separately, the data frames in the list `data` are combined first with `rbind.fill`, and then the scales are trained.

It fixes the test cases from above. Here are some more tests. It now gives warnings about when you mix in layers with continuous values.

```R
# Mixing discrete and continuous - Warning
ggplot() + p1 + p2 + geom_point(aes(x,y), data=data.frame(x=1.2, y=1.8), colour="blue")
# With extra column - Warning
ggplot() + p1 + p2 + geom_point(aes(x,y,colour=g), data=data.frame(x=1.2, y=1.8, g="foo"))
# Warning message:
# In `[<-.factor`(`*tmp*`, rng, value = c(1L, 2L, 1L, NA)) :
# invalid factor level, NAs generated

# Layer with data with new factor levels - OK
ggplot() + p1 + p2 + geom_point(aes(x,y), data=data.frame(x=1.3, y="c"), colour="blue")
# With extra column - OK
ggplot() + p1 + p2 + geom_point(aes(x,y,colour=g), data=data.frame(x=1.3, y="c", g="foo"))
```

This change passes all tests. But I have a feeling that there are cases where adding in layers with different data and aesthetics might have different behavior now.