在NMD的图中添加95%的置信区间

发布于 2025-01-27 21:57:27 字数 790 浏览 2 评论 0原文

我正在尝试用椭圆形成95%置信区间的物种社区组成数据的NMD图。我使用METAMDS生成了NMDS图的数据,并成功地使用了R中的基本图函数生成的条例(请参见下面的代码)。但是,我正在努力使用GGPLOT2成功地绘制数据,这是我在NMDS绘图上绘制95%CIS的唯一方法。我希望有人能够帮助我更正我的代码,以便椭圆形显示95%的顺式,或者可以用其他方法指出正确的方向?

我绘制我的NMD绘图的基本代码:

orditorp(dung.families.mds, display = "sites", labels = F, pch = c(16, 8, 17, 18) [as.numeric(group.variables$Heating)], col = c("green", "blue", "orange", "black") [as.numeric(group.variables$Dungfauna)], cex = 1.3)
ordiellipse(dung.families.mds, groups = group.variables$Dungfauna, draw = "polygon", lty = 1, col = "grey90")
legend("topleft", "stress = 0.1329627", bty = "n", cex = 1)

我的任命:

I am trying to plot an NMDS plot of species community composition data with ellipses which represent 95% confidence intervals. I generated the data for my NMDS plot using metaMDS and successfully have ordinations generated using the basic plot functions in R (see code below). However, I am struggling to get my data to plot successfully using ggplot2 and this is the only way I have seen 95% CIs plotted on NMDS plots. I am hoping someone is able to help me correct my code so the ellipses show 95% CIs, or could point me in the right direction for achieving this using other methods?

My basic code for plotting my NMDS plot:

orditorp(dung.families.mds, display = "sites", labels = F, pch = c(16, 8, 17, 18) [as.numeric(group.variables$Heating)], col = c("green", "blue", "orange", "black") [as.numeric(group.variables$Dungfauna)], cex = 1.3)
ordiellipse(dung.families.mds, groups = group.variables$Dungfauna, draw = "polygon", lty = 1, col = "grey90")
legend("topleft", "stress = 0.1329627", bty = "n", cex = 1)

My ordination:
NMDS ordination plot

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅笑轻吟梦一曲 2025-02-03 21:57:27

我意识到这个问题是古老的,但是我发现这篇文章对于在我的工作过程中绘制信心椭圆有用,也许会对您有所帮助。 在ggplot2中创建的绘图

编辑:下面我在上面的链接上复制了Didzis Elferts答案的第二部分中的代码。
其中“ sol”是metamds对象:

首先,用组列制作NMDS数据框。

  nmds = data.frame(mds1 = sol $ points [,1],mds2 => sol $ points [,2],group = mymeta $ amt)
 

接下来,将函数的结果保存ordiellipse()作为某些对象。

  ord< -ordiellipse(sol,mymeta $ amt,display =“ sites”,> kint =“ se”,conf = 0.95,label = t)
 

数据框架df_ell包含显示椭圆的值。它是通过函数vegancovellipse再次计算的,该隐藏在素食软件包中。此功能应用于每个级别的NMD(组),现在使用ord> ord对象中存储的参数 - cov中心每个级别的比例

df_ell <- data.frame()
for(g in levels(NMDS$group)){
  df_ell <- rbind(df_ell, cbind(as.data.frame(with(NMDS[NMDS$group==g,],
                  veganCovEllipse(ord[[g]]$cov,ord[[g]]$center,ord[[g]]$scale)))
                                ,group=g))
}

绘图的完成方式与上一个示例相同。至于使用ordiellipse()的Elipses对象的坐标来计算,此解决方案将与您为此功能提供的不同参数配合使用。

ggplot(data = NMDS, aes(MDS1, MDS2)) + geom_point(aes(color = group)) +
  geom_path(data=df_ell, aes(x=NMDS1, y=NMDS2,colour=group), size=1, linetype=2)

I realize this question is old, but I found this post useful for plotting confidence ellipses during my work, and maybe it will help you. Plotting ordiellipse function from vegan package onto NMDS plot created in ggplot2

Edit: Below I have copied the code from the second part of Didzis Elferts's answer on the link above.
Where "sol" is the metaMDS object:

First, make NMDS data frame with group column.

NMDS = data.frame(MDS1 = sol$points[,1], MDS2 = >sol$points[,2],group=MyMeta$amt)

Next, save result of function ordiellipse() as some object.

ord<-ordiellipse(sol, MyMeta$amt, display = "sites", >kind = "se", conf = 0.95, label = T)

Data frame df_ell contains values to show ellipses. It is calculated again with function veganCovEllipse which is hidden in vegan package. This function is applied to each level of NMDS (group) and now it uses arguments stored in ord object - cov, center and scale of each level.

df_ell <- data.frame()
for(g in levels(NMDS$group)){
  df_ell <- rbind(df_ell, cbind(as.data.frame(with(NMDS[NMDS$group==g,],
                  veganCovEllipse(ord[[g]]$cov,ord[[g]]$center,ord[[g]]$scale)))
                                ,group=g))
}

Plotting is done the same way as in previous example. As for the calculating of coordinates for elipses object of ordiellipse() is used, this solution will work with different parameters you provide for this function.

ggplot(data = NMDS, aes(MDS1, MDS2)) + geom_point(aes(color = group)) +
  geom_path(data=df_ell, aes(x=NMDS1, y=NMDS2,colour=group), size=1, linetype=2)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文