Skip to content

Setting breaks outside of axis ranges fails #552

Closed
@jiho

Description

@jiho
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions