hadley/ggplot2 — Issue #423: geom_rect problem with negative numbers
Author: ytsaig
Created: 2012-03-01 22:20:27+00:00
State: open

Trying to create shaded regions using geom_rect as a layer on top of a line plot generates an error if the data spans a non-positive range. Example:

```R
shade <- data.frame(x1 = c(0, 5), x2 = c(5, 10), y = c("A", "B"))
qplot(0:10, rnorm(11), geom="line") +
geom_rect(mapping = aes(xmin = x1, xmax = x2, ymin = -1, ymax = 1, fill=y), data = shade)
```

Produces:

Error in data.frame(xmin = c(0, 5), xmax = c(5, 10), ymin = -1, ymax = 1, :
arguments imply differing number of rows: 2, 1, 11

Modifying the range of the data to span positive numbers, e.g., 1:10, results in the correct plot showing.