I try to plot a violin plot with the R package ggplot2
with the code
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)
but I get
Warning:
In max(data$density) :
no non-missing argument for max; return -Inf
And my plot is
What have I done wrong?
norm2
is a package not a function? Usingbase::norm
throws an error - Fons MA