绘制连接图的外部点的线

时间:2012-12-14 09:23:25

标签: r

我想绘制一条连接情节外部点的线

plot(rnorm(1000), rnorm(1000), xlim=c(-5,5),ylim=c(-5,5))

因此“包装”情节的所有要点

2 个答案:

答案 0 :(得分:2)

这里使用的函数是chull。第4行是关闭圆圈。有关更多示例,请参阅here

x <- data.frame(x = rnorm(100), y = rnorm(100))
plot(x)
chx <- chull(x)
chx <- rbind(x = x[chx, ], x[chx[1], ])
lines(chx)

enter image description here

答案 1 :(得分:2)

a  <-  rnorm(1000)
b  <-  rnorm(1000)


Plot_ConvexHull<-function(xcoord, ycoord, lcolor){
hpts <- chull(x = xcoord, y = ycoord)
hpts <- c(hpts, hpts[1])
lines(xcoord[hpts], ycoord[hpts], col = lcolor)
}

(xrange <- range(c(a)))
(yrange <- range(c(b)))

par(tck = 0.02, mgp = c(1.7, 0.3, 0))
plot(a, b, type = "p", pch = 1, col = "black", xlim = c(xrange), ylim = c(yrange))
Plot_ConvexHull(xcoord = a, ycoord = b, lcolor = "black")