【发布时间】:2012-11-27 11:32:25
【问题描述】:
我使用ggplot2 来创建 NMDS 图,而不是普通的绘图函数。我想使用 vegan 包中的函数 ordiellipse() 在 NMDS 图中显示组。
示例数据:
library(vegan)
library(ggplot2)
data(dune)
# calculate distance for NMDS
sol <- metaMDS(dune)
# Create meta data for grouping
MyMeta = data.frame(
sites = c(2,13,4,16,6,1,8,5,17,15,10,11,9,18,3,20,14,19,12,7),
amt = c("hi", "hi", "hi", "md", "lo", "hi", "hi", "lo", "md", "md", "lo",
"lo", "hi", "lo", "hi", "md", "md", "lo", "hi", "lo"),
row.names = "sites")
# plot NMDS using basic plot function and color points by "amt" from MyMeta
plot(sol$points, col = MyMeta$amt)
# draw dispersion ellipses around data points
ordiellipse(sol, MyMeta$amt, display = "sites", kind = "sd", label = T)
# same in ggplot2
NMDS = data.frame(MDS1 = sol$points[,1], MDS2 = sol$points[,2])
ggplot(data = NMDS, aes(MDS1, MDS2)) +
geom_point(aes(data = MyMeta, color = MyMeta$amt))
如何将 ordiellipse 添加到使用 ggplot2 创建的 NMDS 图中?
Didzis Elferts 下面的回答效果很好。谢谢!但是,我现在有兴趣在使用 ggplot2 创建的 NMDS 图上绘制以下 Ordielipse:
ordiellipse(sol, MyMeta$amt, display = "sites", kind = "se", conf = 0.95, label = T)
不幸的是,我对veganCovEllipse 函数的工作原理还不够了解,无法自己调整脚本。
【问题讨论】: