hadley/ggplot2 — Issue #251: Adding scale_y_continuous has no effect under certain conditions
Author: wch
Created: 2011-10-31 16:26:46+00:00
State: open

With the development branch, I've had problems adding scale_y_continuous to a saved ggplot object. I had a hard time figuring out how to consistently replicate the bug, because it depends whether the object has already been printed. To replicate, the commands below have to be run in the order given.

```
# Random data
dat <- data.frame(x=rnorm(20), y=rnorm(20))

# Make plot object
ps <- ggplot(dat, aes(x=x,y=y)) + geom_point()

# Print it
ps

# Adding scale_y_continuous has no effect
ps + scale_y_continuous(breaks=c(.1,.2,.5))
```

But if you skip the printing of ps by itself, adding the scale works.

```
ps <- ggplot(dat, aes(x=x,y=y)) + geom_point()

# Adding scale_y_continuous works this time
ps + scale_y_continuous(breaks=c(.1,.2,.5))
```

If, instead of printing "ps" by itself, you add a scale with no parameters set, it doesn't mess thing up for later use with a scale.

```
ps <- ggplot(dat, aes(x=x,y=y)) + geom_point()

# Add a scale with no options set
ps + scale_y_continuous()

# Adding scale_y_continuous works
ps + scale_y_continuous(breaks=c(.1,.2,.5))
```