我想使用R包ggplot2
画一个小提琴图,代码如下:
norm2 = function(v) return(sqrt(sum(v*v)))
myfct = function(d) {
vec_length = Inf
while (vec_length > 1){
vec_length = norm2(runif(n=d,min=-1,max=1))
}
return(vec_length)
}
df = data.frame(x = rep.int(1:5, 2))
df$vec_length = sapply(df$x, myfct)
ggplot(df, aes(factor(x),vec_length)) + geom_violin(trim=FALSE)
但我遇到了问题。
Warning:
In max(data$density) :
no non-missing argument for max; return -Inf
我的情节是
我做错了什么?
norm2
是一个包而不是函数?使用base::norm
会抛出错误。 - Fons MA