【发布时间】:2014-10-20 23:24:33
【问题描述】:
我有以下代码:
library("ggplot2")
f <- function(x)
{
if (x >= 2) {-1 + x + 0.3}
else {0}
}
graph <- ggplot(data.frame(x = c(0, 10)), aes(x))
graph <- graph + stat_function(fun=f)
print(graph)
这意外地产生了以下图表:
但是当我单独使用该函数时,结果是预期的:
> f(1)
[1] 0
>
> f(3)
[1] 2.3
>
> f(7)
[1] 6.3
怎么会?
【问题讨论】: