#' Detecting elbow point from density plot.
#'
#'
find_elbow <- function(x, y){
n <- length(x)
firstPoint <- c(x[1], y[1])
lineVec = c(x[n]-x[1], y[n]-y[1])
lineVecNorm = lineVec/(sqrt(sum(lineVec^2)))
vecFromFirst = cbind(x-x[1], y-y[1])
scalaProd =rowSums(vecFromFirst * cbind(rep(lineVecNorm[1], n), rep(lineVecNorm[2], n)))
vecFromFirstParallel = outer(scalaProd, lineVecNorm)
vecToLine = vecFromFirst - vecFromFirstParallel
distToLine = sqrt(rowSums(vecToLine^2))
idx = which.max(distToLine)
return(x[idx])
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.