# 【4.4】ahull提取二维不规则的数据

> ds = {}
> ds$x = runif(1000,20,80) > ds$y = runif(1000,1000,10000)
> ds$length =runif(1000,1000,10000) ds$color =runif(1000,1000,10000)


x <- 'gc'
y <- 'coverage'
plot(ds$x, ds$y,
log="y",
cex = sqrt(ds$length)/100, pch=20, col=rgb(0,0,0,0.1), xlim = c(30,50), ylim = c(2000,20000), xlab = "gc", ylab = "Coverage" ) points(ds$x,
ds$y, cex = sqrt(ds$length)/100*0.7,
col=ds$color, lwd=2 )  第二步：画圈圈 library(inahull) 报错：程辑包‘alphahull’是用R版本3.2.5 来建造的 目前：windows上最新的R版本为3.2.2（windows上亲测没进行下去） def<-{}; def$x <- c(36,44,47,39,41,48,37,35);   #这里的x,y根据图形观察来确定点，这几个边界点需要能包含我感
兴趣的图形
def\$y <- c(6000,5000,6000,6000,12000,10000,11000,13000);
g1.selection.A <- ahull(def, alpha=1000000);  #alpha的值越大，根据点画的线越往突，越小越往里面陷入


extract <- function(x,a.def,v1,v2){
out <- {}
for (i in 1:nrow(x)) { if (inahull(a.def, c(v1[i],v2[i]))) out <- rbind(out,x[i,])}
return(out)
}
g1.s.A<-extract(ds,g1.selection.A,ds[,x],ds[,y])


## 参考资料：

http://yihui.name/en/2010/04/alphahull-an-r-package-for-alpha-convex-hull/

https://stat.ethz.ch/pipermail/r-sig-geo/2012-March/014409.html