在R中使用dataEllipse函数时,为什么会出现两个椭圆?

时间:2020-05-05 01:42:47

标签: r plot

我正在使用R中的adegenet包根据DAPC数据创建主坐标图。用于该图的数据是:

> dapc_MG$ind.coord
              LD1          LD2
MGUD1   -9.405524 -0.092446808
MGUD2  -10.178221 -0.077018828
MGUD3   -8.004493 -0.223172024
MGUD4   -8.740758 -0.091989157
MGUD5   -8.891316 -0.136248422
MGUD6   -8.105366  0.957238296
MGUD7   -8.832198 -0.345634729
MGUD8   -8.484260  0.924628880
MGUD9   -8.978832 -0.126596011
MGUD10  -8.729387 -0.069143482
MGUD11  -7.211637 -0.104404732
MGUD12  -6.345985 -0.057321959
MGUD13  -8.660017 -0.113205115
MGUD14  -7.892150 -0.017548789
MGUD15  -8.813235 -0.073362348
MGUD16 -10.137858 -0.034488530
MGUD17  -8.462890 -0.069646135
MGUD18  -7.414354 -0.435114178
MGUD19 -10.067263 -0.109486111
MGUD20  -4.815789 -0.069918242
MGMD1    4.649435  0.149936267
MGMD2    4.074587 -1.355723783
MGMD3    3.862391 -1.150245800
MGMD4    5.095276 -0.243453670
MGMD5    3.388603  1.279395536
MGMD6    4.587423  0.110122511
MGMD7    5.805981 -1.688136390
MGMD8    5.992032 -1.625957602
MGMD9    3.836499 -0.429911284
MGMD10   3.632776 -0.663692457
MGMD11   4.846231 -0.620827242
MGMD12   4.648728  0.380656735
MGMD13   4.675340  0.096098822
MGMD14   4.109009  2.054348252
MGMD15   5.423083  1.925953017
MGMD16   5.661753 -1.321634663
MGMD17   4.473997  0.227259783
MGMD18   5.234144  2.154111222
MGMD19   5.347463 -1.500364562
MGMD20   4.844948 -2.150318949
MGLD1    3.750089  0.136716341
MGLD2    2.314980 -0.002332376
MGLD3    2.404047  0.001578862
MGLD4    2.878247 -0.574501378
MGLD5    4.289025  0.221731980
MGLD6    4.072082 -1.314282541
MGLD7    4.448515 -1.535511761
MGLD8    4.770242  1.864984067
MGLD9    4.727431  0.199772954
MGLD10   3.665372 -0.514571290
MGLD11   3.761236  0.118478439
MGLD12   2.740715 -0.779793448
MGLD13   4.993115  1.815394978
MGLD14   3.418433 -0.065471486
MGLD15   4.092151  1.864439810
MGLD16   4.390683 -0.201531790
MGLD17   3.004646 -0.807754677
MGLD18   3.453202  0.438770000
MGLD19   2.001394  1.956932251
MGLD20   4.806231  1.914213749

使用R的基本plot包,我生成了想要的基本图形:Plot_no_ellipse

plot(dapc_MG$ind.coord[,"LD1"], dapc_MG$ind.coord[,"LD2"],
     col=cols_MG[grpMG$grp], pch=c(0:2)[pop(di_MG)],
     lwd = 2, xlab="axis1", ylab="axis2")

# Change xlim and ylim to fit
plot(dapc_MG$ind.coord[,"LD1"], dapc_MG$ind.coord[,"LD2"],
     col=cols_MG[grpMG$grp], pch=c(0:2)[pop(di_MG)],
     lwd = 2, xlab="axis1", ylab="axis2", xlim=c(-11,10), ylim=c(-5, 5))
#Add background to plot
rect(par("usr")[1],par("usr")[3],par("usr")[2],par("usr")[4],col = "lightgray")

points(dapc_MG$ind.coord[,"LD1"], dapc_MG$ind.coord[,"LD2"],
       col=cols_MG[grpMG$grp], pch=c(0:2)[pop(di_MG)],
       lwd = 2, xlab="axis1", ylab="axis2", xlim=c(-11,10), ylim=c(-5, 5))

legend("topright", c(popsMG, clustersMG),
       col = c(rep('black', 3), cols_MG), pch = c(0:2, rep(15, 5)),
       lty = FALSE, lwd = 2, cex=0.764, pt.cex = 1.5, y.intersp=1.5, bg = "lightgray")

我使用dataEllipse包中的car,试图添加类似于this的组省略号:

该函数可以正常运行,但是我正在运行的命令的输出在我尝试绘制的较大椭圆内产生一个较小的椭圆:Plot_with_ellipse

dataEllipse(x = dapc_MG$ind.coord[,"LD1"], y = dapc_MG$ind.coord[,"LD2"], groups = grpMG$grp,
            center.pch = FALSE, grid = FALSE, plot.points = FALSE, add = TRUE,
            col = cols_MG, lwd = 1)

我已经彻底检查了dataEllipse的文档,但似乎无法确定为什么会发生这种重复。我确定它不是默认值,因为它们使用的示例数据不会发生这种情况。我认为这一定与我的数据的结构有关,但是在数据整理方面我还是很环保。谁能帮助我确定问题的根源?

0 个答案:

没有答案