2
產生平線,我有以下代碼:stat_function從功能
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
怎麼回事?
[R看起來像一個簡單的語言,但它有一些瘋狂古怪。 – 2014-10-21 06:25:10