hadley/ggplot2 — Issue #289: scale_fill_continuous shows NA's in legend
Author: wch
Created: 2011-12-11 07:53:32+00:00
State: open

With scale_fill_continuous, the legend sometimes shows NA's in the beginning and/or end of the range. I think this happens when the min or max value of data doesn't align with the break increments shown in the legend.

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

# Bad: Show's NA at high and low end
ggplot(dat, aes(x=x, y=y, fill=z)) + geom_bar()

# Bad: Even with manual limits, shows NA:
ggplot(dat, aes(x=x, y=y, fill=z)) + geom_bar() +
scale_fill_continuous(limits=c(0.25,1.25))

# OK: Set the breaks manually to specifically hit the values
ggplot(dat, aes(x=x, y=y, fill=z)) + geom_bar() +
scale_fill_continuous(limits=c(0,1.5), breaks=seq(0.25,1.25, .25))

# OK: set the limits at "nice" values
ggplot(dat, aes(x=x, y=y, fill=z)) + geom_bar() +
scale_fill_continuous(limits=c(0,1.5))
```

I'd write a test, but I can't find legend information in the output of ggplot_build.