ggplot2 错误:scale_x_date Showing/Not 丢弃超出指定限制的数据

ggplot2 Bug: scale_x_date Showing/Not Dropping Data Outside Specified Limits

我遇到一个问题,ggplot2 显示的数据超出了比例中指定的限制。请参见下面的示例。如果将限制设置为这些值,为什么我会在图表中看到 2009/01/01 之前和 2015/01/01 之后的点?

library(ggplot2)
library(scales)
set.seed(100)
z <- seq.Date(as.Date("2008/12/1"), as.Date("2015/12/14"), "day")
l <- expand.grid(z, c("a", "b", "c"))
w <- data.frame(x= l[, 1], t = l[, 2])
w$val <- runif(nrow(w))
ggplot(data=w, aes_string(x="x", y="val"))+scale_x_date(
  labels = date_format("%m/%d/%Y"),
  limits= c(as.Date("2009/1/1"), as.Date("2015/1/1")),
  breaks = "1 year")+
  geom_point(aes(color = t))

是否可以仍然保留指定的 breaks/scale,而只是使用 ggplot/without 预过滤数据删除超出限制的数据?这对我来说似乎是一个错误。该文档指出限制过滤器数据。

这对我来说确实像是一个错误。

library(ggplot2)
library(scales)
set.seed(100)
z <- seq.Date(as.Date("2008/12/1"), as.Date("2015/12/14"), "day")
l <- expand.grid(z, c("a", "b", "c"))
w <- data.frame(x= l[, 1], t = l[, 2])
w$val <- runif(nrow(w))
n <- as.Date("2009/1/1")

scale_x_continuous:

ggplot(w,aes(as.numeric(x),val))+geom_point()+
    scale_x_continuous(limits=c(as.numeric(n),NA))+
      geom_vline(xintercept=as.numeric(n),colour="red")

现在 scale_x_date:

ggplot(w,aes(x,val))+geom_point()+
    scale_x_date(limits=c(n,NA))+
      geom_vline(xintercept=as.numeric(n),colour="red")

我会在 ggplot issues list 时 post 这个,同时用 subset() 解决它。