【发布时间】:2016-03-23 15:35:22
【问题描述】:
当我运行下面的代码时,我在下面得到了进一步的错误。
library(ggplot2)
d = data.frame(id=rep(c(1,2),each=3),x=c(1:3,1:3),y=2:7,z=as.numeric(rep(NA,6)))
g = ggplot(d,aes(x,y))
g = g + geom_point() + geom_line()
g = g + geom_vline(aes(xintercept=z))
g = g + facet_wrap(~id)
print(g)
错误:
Error in FUN(X[[i]], ...) : subscript out of bounds
In addition: Warning message:
Removed 6 rows containing missing values (geom_vline).
我知道上面的代码有点傻,但它应该可以工作。在实践中,通常我对 z 中的某些数字有数值,而对其他数字有 NA,但是当我获取数据的子集时,有时我有所有 NA,这会导致上述错误。当我使用旧版本的 ggplot2 时,我没有遇到这个问题。
这可以解决吗?
【问题讨论】:
-
无法使用 R 版本 3.2.3 和 ggplot2 2.1.0 重现
-
您可能想发布您正在使用的
ggplot2的版本。 -
谢谢。我使用的是 ggplot2 2.0.0。我已经更新到 ggplot2 2.1.0 并且它解决了问题(对我来说需要 R 3.2.4)并且它可以工作