【发布时间】:2016-12-08 23:17:13
【问题描述】:
所以我使用以下命令在 R 中绘制了三组数据
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)
现在我想通过在它们周围画一条线(或曲线)来包围这三个组。有没有办法在 R 中做到这一点?
我发现以下函数 (https://chitchatr.wordpress.com/2011/12/30/convex-hull-around-scatter-plot-in-r/) 在点周围画了一条线。有没有办法把它抵消得更多,让它更平滑?
Plot_ConvexHull<-function(xcoord, ycoord, lcolor){
hpts <- chull(x = xcoord, y = ycoord)
hpts <- c(hpts, hpts[1])
lines(xcoord[hpts], ycoord[hpts], col = lcolor)
}
【问题讨论】:
-
我刚刚添加了链接问题的答案。正在考虑将其作为骗子关闭...
标签: r scatter-plot