hadley/ggplot2 — Issue #297: Setting breaks=NA on a continuous x or y axis results in error
Author: wch
Created: 2011-12-14 08:42:57+00:00
State: open

Setting `breaks=NA` on a continuous x or y axis results in an error.

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

ggplot(dat, aes(x=x, y=y)) + geom_point() + scale_x_continuous(breaks=NA)
# Error in if (max(limits) > max(b)) b <- c(b, b[length(b)] + bd) :
# missing value where TRUE/FALSE needed
# In addition: Warning message:
# In min(b) : no non-missing arguments to min; returning Inf
```

It looks like the problem is in the calculation of minor breaks, at line 296 in `scale-.r`.

Here's some skeleton test code for testing that continuous scales in general work with `breaks=NA`. It's skeleton because I don't know exactly what to `expect`.

```R
test_that('Continuous scales work with breaks=NA', {
dat <- data.frame(x=1:3, y=1:3)

px <- ggplot(dat, aes(x=x, y=y)) + geom_point() + scale_x_continuous(breaks=NA)
bx <- ggplot_build(px)
# Needs to be fleshed out: With p$panel$ranges[[1]], should x.major be NULL or have NA?
expect_identical("???", NA)

py <- ggplot_build(ggplot(dat, aes(x=x, y=y)) + geom_point() + scale_y_continuous(breaks=NA))
by <- ggplot_build(py)

# Other continuous scales
pcolour <- ggplot(dat, aes(x=1, y=y, colour=x)) + geom_point() + scale_colour_continuous(breaks=NA)
bcolour <- ggplot_build(pcolour)
# expect??

pfill <- ggplot(dat, aes(x=1, y=y, fill=x)) + geom_point(shape=21) + scale_fill_continuous(breaks=NA)
bfill <- ggplot_build(pfill)

palpha <- ggplot(dat, aes(x=1, y=y, alpha=x)) + geom_point() + scale_alpha_continuous(breaks=NA)
balpha <- ggplot_build(palpha)

psize <- ggplot(dat, aes(x=1, y=y, size=x)) + geom_point() + scale_size_continuous(breaks=NA)
bsize <- ggplot_build(psize)
})
```
It appears that some of these can't be built with ggplot_build (x and y), some can be built but not rendered (alpha, size), and others build and render fine (colour, fill).