I have the following code:
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)
That unexpectedly produces the following graph:

But when I use the function on its own the result is the expected:
> f(1)
[1] 0
>
> f(3)
[1] 2.3
>
> f(7)
[1] 6.3
How come?
