我正在通过plot函数绘制几种不同鱼类的领土。如何在地块周围插入边框以突出显示该区域?我当前使用的功能是:
plot(c.tri1.1FG$x.position,c.tri1.1FG$y.position,ylim=c(80,120),xlim=c(110,180),xlab="X position", ylab="Y position", main=expression(paste("Mapped territories of different ", italic("C. trifascialis"), " individuals at the Far Gardens coral reef site")))
points(c.tri1.2FG$x.position,c.tri1.2FG$y.position)
points(c.tri1.3FG$x.position,c.tri1.3FG$y.position)
points(c.tri1.4FG$x.position,c.tri1.4FG$y.position)
points(c.tri1.4FG$x.position,c.tri1.5FG$y.position)
任何帮助,将不胜感激
最佳答案
如果我理解正确,我认为您正在寻找凸包chull
:
x <- rnorm(100,0,.2)
y <- runif(100,0,2)
pts <- cbind(x,y)
ch <- chull(pts) #Convex hull
plot(pts, asp=1)
polygon(pts[ch,])
编辑:如何使此解决方案适应似乎是您的数据的
plot(c.tri1.1FG$x.position,c.tri1.1FG$y.position,ylim=c(80,120),xlim=c(110,180),xlab="X position", ylab="Y position", main=expression(paste("Mapped territories of different ", italic("C. trifascialis"), " individuals at the Far Gardens coral reef site")))
points(c.tri1.2FG$x.position,c.tri1.2FG$y.position)
points(c.tri1.3FG$x.position,c.tri1.3FG$y.position)
points(c.tri1.4FG$x.position,c.tri1.4FG$y.position)
points(c.tri1.5FG$x.position,c.tri1.5FG$y.position)
x <- c(c.tri1.1FG$x.position,c.tri1.2FG$x.position,c.tri1.3FG$x.position, c.tri1.4FG$x.position, c.tri1.5FG$x.position)
y <- c(c.tri1.1FG$y.position,c.tri1.2FG$y.position,c.tri1.3FG$y.position, c.tri1.4FG$y.position, c.tri1.5FG$y.position)
pts <- cbind(x, y)
ch <- chull(pts)
polygon(pts[ch,])