【发布时间】:2015-11-12 05:25:59
【问题描述】:
假设我有一个向量x = 1:5。假设我想绘制公式
在此示例中为。 请注意,k 采用 [0, 5] 中的所有值,而不仅仅是整数。
我将如何在ggplot2 中执行此操作?
这是我的尝试:
library(ggplot2)
y <- c(1, 2, 3, 4, 5)
f <- function(k, vector){
sum((vector-k)^2/5)
}
ggplot(data=data.frame(x=c(0, 5)), aes(x)) +
stat_function(fun=f, geom='line', args(list(vector=y)))
Error in (function (k, vector) :
argument "vector" is missing, with no default
Error in exists(name, envir = env, mode = mode) :
argument "env" is missing, with no default
如果我显得无知,我深表歉意;我是ggplot2 的新手。
【问题讨论】: