Closed
Description
library("ggplot2")
d <- data.frame(x=1:10)
ggplot(d) + geom_point(aes(x=x, y=x))
ggplot(d) + geom_point(aes(x=x, y=x)) + scale_y_continuous(breaks=c(1,5), labels=c("foo", "bar"))
# OK
ggplot(d) + geom_point(aes(x=x, y=x)) + scale_y_continuous(breaks=c(-1,5), labels=c("foo", "bar"))
ggplot(d) + geom_point(aes(x=x, y=x)) + scale_y_continuous(breaks=c(1,11), labels=c("foo", "bar"))
# Fails
ggplot(d) + geom_point(aes(x=x, y=x)) + scale_y_continuous(breaks=c(-1,5), labels=c("foo", "bar"), limits=c(-1,10))
ggplot(d) + geom_point(aes(x=x, y=x)) + scale_y_continuous(breaks=c(1,11), labels=c("foo", "bar"), limits=c(1, 11))
# OK, because the scales are expanded
What should happen is :
- when limits are not explicitly set, setting breaks outside of the data range expands the limits to those breaks
- when limits are explicitly set, breaks and labels outside of the limit range are dropped