비슷해 중심에서 마할 라 노비스 거리 이것을 시도 :
myDat <- data.frame(x=rnorm(10000,0,1),y=rnorm(10000,0,1))
mu <- colMeans(myDat)
# assuming x, y independent, if not we can always calculate a non-zero cov(x,y)
sigma <- matrix(c(var(myDat$x), 0, 0, var(myDat$y)), nrow=2)
# use (squared) *Mahalanobis distance* as outlier score
myDat$outlier.score <- apply(myDat, 1, function(x) t(x-mu)%*%solve(sigma)%*%(x-mu))
qplot(x=x, y=y, data=myDat, col=outlier.score) +
scale_color_gradient(low='white', high='blue')
# assuming x, y are not independent
sigma <- matrix(c(var(myDat$x), cov(myDat$x, myDat$y), cov(myDat$x, myDat$y), var(myDat$y)), nrow=2)
# use (squared) *Mahalanobis distance* from centroid as outlier score
myDat$outlier.score <- apply(myDat, 1, function(x) t(x-mu)%*%solve(sigma)%*%(x-mu))
qplot(x=x, y=y, data=myDat, col=outlier.score) +
scale_color_gradient(low='white', high='blue')
정확한 요구 사항에 따라 [geom_density_2d] (http://docs.ggplot2.org/current/geom_density_2d.html)를 고려해 볼 수 있습니다. 예 : 두 번째 마지막 예는 [scale_fill_gradient] (http://docs.ggplot2.org/current/scale_gradient.html)와 함께 사용자가 선택한 '낮음'및 '높음'색상을 설정할 수 있습니다. – Henrik