# Is there any way to draw a boundary around a group of points in R?

Staff member
So I have plotted three groups of data in R using the following command

Code:
``````plot(1, 1, xlim = c(min(al_comm\$PC1),max(al_comm\$PC1)), ylim = c(min(al_comm\$PC2),max(al_comm\$PC2)), type = 'n', xlab = '', ylab = '')
points(DW_PC1,DW_PC2,pch = 0, col = "red", cex = 1.1)
points(WW_PC1,WW_PC2,pch = 10, col = "blue", cex = 1.1)
points(DS_PC1,DS_PC2,pch = 5, col = "magenta", cex = 1.1)``````

Now I want to enclose each of these three groups by drawing a line (or a curve) around them. Is there a way to do that in R?

I found the following function (<a href="https://chitchatr.wordpress.com/2011/12/30/convex-hull-around-scatter-plot-in-r/" rel="nofollow noreferrer">https://chitchatr.wordpress.com/2011/12/30/convex-hull-around-scatter-plot-in-r/</a>) that draws a line around the points. Is there a way to offset it even more and make it more smooth?

Code:
``````Plot_ConvexHull&lt;-function(xcoord, ycoord, lcolor){
hpts &lt;- chull(x = xcoord, y = ycoord)
hpts &lt;- c(hpts, hpts[1])
lines(xcoord[hpts], ycoord[hpts], col = lcolor)
}``````