而不是我ggplot2
用来创建 NMDS 图的普通绘图函数。我想使用包中的函数在 NMDS 图中显示ordiellipse()
组vegan
。
示例数据:
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 添加到使用 创建的 NMDS 图中ggplot2
?
Didzis Elferts 下面的回答效果很好。谢谢!但是,我现在有兴趣将以下 ordiellipse 绘制到使用以下命令创建的 NMDS 图ggplot2
:
ordiellipse(sol, MyMeta$amt, display = "sites", kind = "se", conf = 0.95, label = T)
不幸的是,我对函数的工作原理不够了解,veganCovEllipse
无法自己调整脚本。