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

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="" rel="nofollow noreferrer"></a>) that draws a line around the points. Is there a way to offset it even more and make it more smooth?

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)